News for hackers. Stuff that matters.
Re:Computer Scientists’ Trivia by Koshkin on Thursday February 02, 2017 @10:40AM (#13551235)
More accurately, sizeof(char) is always 1. This is simply because sizeof returns the size of the object measured in terms of the equivalent number of chars (rather than 'bytes').
Re:Computer Scientists’ Trivia by jwilk on Thursday February 02, 2017 @11:09AM (#13551542)
Perhaps your notion of what a byte is different, but according to the C99 standard:

- sizeof returns size in bytes;

- sizeof (char) == 1;

- one byte has CHAR_BIT bits;

- CHAR_BIT >= 8.

Re:Computer Scientists’ Trivia by John23832 on Thursday February 02, 2017 @12:07PM (#13552141)
> - one byte has CHAR_BIT bits;

Can you link a reference to this? Seems backwards/weird.

Re:Computer Scientists’ Trivia by AnimalMuppet on Thursday February 02, 2017 @12:04PM (#13552107)
So per C99, a byte can have more than 8 bits? My mind boggles...
Re:Computer Scientists’ Trivia by Someone on Thursday February 02, 2017 @12:49PM (#13552645)
For 36-bit CPUs, the 9-bit byte was a natural choice (as was storing 6 characters of a more limited character set in a 36-bit word)
Re:Computer Scientists’ Trivia by AnimalMuppet on Thursday February 02, 2017 @01:04PM (#13552812)
Ah, yes, 36-bit. I had forgotten about that, despite my mother having worked on such systems.
Re:Computer Scientists’ Trivia by John23832 on Thursday February 02, 2017 @10:47AM (#13551311)
That's not true. sizeof(char) returns 1 because the size of a char in that implementation is 1 byte and C doesn't directly address bits.
Re:Computer Scientists’ Trivia by Koshkin on Thursday February 02, 2017 @10:53AM (#13551365)
Well, according to the Wikipedia article about sizeof,

In the programming languages C and C++, the unary operator sizeof generates the size of a variable or datatype, measured in the number of char size storage units required for the type. As such, the construct sizeof (char) is guaranteed to be 1.

Re:Computer Scientists’ Trivia by John23832 on Thursday February 02, 2017 @11:08AM (#13551528)
I stand corrected.
Re:Computer Scientists’ Trivia by Koshkin on Thursday February 02, 2017 @11:25AM (#13551715)
You were correct after all. The C99 standard does indeed talk about sizeof in terms of bytes!
Re:Computer Scientists’ Trivia by John23832 on Thursday February 02, 2017 @11:34AM (#13551813)
I guess this is one of those few times that we can say we were both correct.