News for hackers. Stuff that matters.
Re:Can code that is valid in both C and C++ produce differen... by CJefferson on Monday October 15, 2012 @05:58AM (#4654373)
It would be a weird machine!

sizeof(char) has to be 1 in both C and C++ (5.3.3, para 1), and this is the smallest addressable amount, so should be a byte on most machines. "Plain ints have the natural size suggested by the architecture of the execution environment", which on most modern machines is not a single byte, but 4 or 8. Also C++ says that an int must store INT_MAX, which according to the C standard has to be at least 32767.

So you could have sizeof(char)=sizeof(int), but it would have to be on at least 16-bit addressable machine, with a natural machine size of 16-bits. Possible but very unusual.

(For the recent draft of the C++ standard which I refering to, see: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n337... )

Re:Can code that is valid in both C and C++ produce differen... by danh1979 on Monday October 15, 2012 @09:04AM (#4654857)
The compiler for the TI C55x family [1] of fixed-point DSPs is implemented that way: sizeof(char) == 1 and sizeof(int) == 1, both 16-bit fields. A practical consequence is that you can't easily use the same struct header files, for example, on a more conventional platform. Another is that ASCII strings use twice the space.

[1] http://processors.wiki.ti.com/index.php/Category:C5000