News for hackers. Stuff that matters.
Re:So you think you know C? by swolchok on Tuesday November 08, 2016 @04:08PM (#12903956)
sizeof(char) has to be 1, but char doesn't have to be 1 byte in size. It's more correct to say that sizeof(foo) returns a result relative to sizeof(char).
Re:So you think you know C? by pksadiq on Tuesday November 08, 2016 @07:37PM (#12905244)
> but char doesn't have to be 1 byte in size

It is, but not required to be an octect. Quoting from the standard (n1570, 3.6):

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

Later in a comment (page 44 in pdf, note 49): A byte contains CHAR_BIT bits

Re:So you think you know C? by breadbox on Tuesday November 08, 2016 @06:56PM (#12905075)
char doesn't have to be 8 bits in size, true, but C basically doesn't give you any way to address memory smaller than a char.
Re:So you think you know C? by boomlinde on Wednesday November 09, 2016 @12:03PM (#12912005)
> C basically doesn't give you any way to address memory smaller than a char

It does, via bit-fields.

Re:So you think you know C? by breadbox on Wednesday November 09, 2016 @12:58PM (#12912721)
Or via the bitwise operators. Still, it is not possible to take the address of a bitfield.
Re:So you think you know C? by boomlinde on Wednesday November 16, 2016 @01:43PM (#12970000)
The difference may be 100% semantics, but when I am using a bit field, I am addressing the particular bits I am interested in via a name, and when I am shifting and masking bits, I am directly manipulating a piece of memory until its value represents the bits that I am interested in.