News for hackers. Stuff that matters.
Re:So you think you know C? by yes_or_gnome on Tuesday November 08, 2016 @05:35PM (#12904567)
Yes, but the term "byte" doesn't tell you much. Most people assume that a byte is 8-bits which isn't true. If the definition the of `char` was `1 octet`, then you could make safer assumptions about "What's the result of `' ' * 13`?".

From ISO/IEC 9899:2011:

  3.6

  byte

  addressable unit of data storage large enough to hold any
  member of the basic character set of the execution
  environment

  NOTE 1 It is possible to express the address of each
  individual byte of an object uniquely.

  NOTE 2 A byte is composed of a contiguous sequence of bits,
  the number of which is implementation-defined. The least 
  significant bit is called the low-order bit; the most
  significant bit is called the high-order bit.
Edit: Reading further into the C11 spec, `5.2.4.2.1 Sizes of integer types <limits.h>`, it says that `CHAR_BIT` must be 8 bits (or larger). A google search suggests there exists some processors that have 16-bit bytes and others that have 32-bit bytes.
Re:So you think you know C? by kps on Tuesday November 08, 2016 @07:49PM (#12905284)
I've also personally encountered 24 for C. That's not the problem with (' '*13) here, though — C doesn't mandate ASCII.
Re:So you think you know C? by ekiru on Tuesday November 08, 2016 @08:25PM (#12905408)
char is also allowed to be a signed type, in which case overflow is undefined behavior.
Re:So you think you know C? by evincarofautumn on Tuesday November 08, 2016 @10:50PM (#12905914)
It’s not because of the signedness of char—not only do character literals have type int, but even if this weren’t a literal, the char would be promoted to (signed) int before the multiplication. But of course the multiplication of two ints can still overflow.
Re:So you think you know C? by qb45 on Wednesday November 09, 2016 @03:13AM (#12907600)
> Most people assume that a byte is 8-bits which isn't true.

It is worth remembering that POSIX (and Windows probably too) mandate 8bit chars so there is no point being defensive about it on these particular platforms. And I kid you not, I have seen people who are. Because "ISO C99 this and that".