Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do not use the sizeof() operator
#5
Well, after reading through C99, it seems every definition of char or a byte I can find is stated as "large enough...", ie at least 8 bits.
On the other hand, there is no text anywhere saying that char is allowed to be larger than 8 bits either.

The only text that is clearly written in the standard regarding this topic is actually the text below the sizeof() operator, which could be
interpreted as a statement of how large the char type is, by using plain logic:

sizeof() shall return the number of bytes of its operand
sizeof(char) shall return 1
Logical conclusion: the size of char is 1 byte

One may argue about whether the sizeof() chapter is a good place to write that definition, but still the text is just as normative as the rest of the standard.
So by that, one could say that 16 bit char is non-standard C. (There is the wchar_t, so there is no reason to make a mess of the ordinary char type...)

Also, there is always a need in embedded programming to communicate with hardware on byte-basis. With a compiler implementing char as 16 bit, you must
write all such code in inline assembler. Therefore I would definitely label such a compiler entirely unsuitable for embedded systems.
<t></t>
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)