Is it possible to change the size of a char ?
For example, a char has size of one byte. Is it possible using preprocessor or a gcc flag to make it, let's say two bytes or anyway the size of char will always be 1 byte ?
Printable View
Is it possible to change the size of a char ?
For example, a char has size of one byte. Is it possible using preprocessor or a gcc flag to make it, let's say two bytes or anyway the size of char will always be 1 byte ?
Big Brother says that a char has the size of two bytes. Therefore, a char has the size of two bytes. Even if sizeof(char) always returns 1, the size of a char is two bytes. 2 + 2 == 5 evaluates to 1.
Okay, why do you want to do this? The C standard defines sizeof(char) == 1. If this can be changed... then everything should be scaled according to what sizeof(char) has been changed to. I do not see any benefit.
Well, the returning part is part of the joke: sizeof is an operator, not a function, so to say "sizeof(char) always returns 1" is inaccurate. That said, one possibility why sizeof(char) == 1 is that all the standard integer types have sizes that are larger than char, except for unsigned char and signed char, both of which have sizes equal to that of char. Therefore, if sizeof(char) is not 1, then there is no standard integer type whose size is exactly 1 byte.Quote:
Originally Posted by ch4
But of course, "Big Brother" could represent a compiler author who wishes to do whatever he/she wants, ignoring the standard in the process. If you obey Big Brother, then whatever happens is up to Big Brother, and we really cannot advise you as to what might happen (e.g., what if Big Brother insisted that INTERCAL is C?)
This question doesn't make much sense. Perhaps you want to use a larger integer type? Or do you want to store strings (char arrays)?
People can have conversations about anything they want, BUT:
If by this you mean, "Are there any standard commands or sequences of standard commands I can issue in a C program to change the size of char or any other standard datatype?" the answer is NO, not if you are using a standards compliant C compiler.
If you are using a compiler which does allow such a thing, it would have to include some new non-standard command(s) to do it, which anything is possible that way, but it is unlikely that it is referred to as a "C compiler" and it would be an untruth to call this new language "C", altho it may also compile normal C programs. In reality this compiler does not exist, and it is very unlikely that someone will create one, either, whether the author goes by the name of "Big Brother" or "Twisted Sister" ;)