Re: C Interpreter and sizeof operator
- From: Skarmander <invalid@xxxxxxxxxxxxxx>
- Date: Wed, 30 Nov 2005 02:10:20 +0100
Christian Bau wrote:
In article <438ce9a7$0$11070$e4fe514c@xxxxxxxxxxxxxx>, Skarmander <invalid@xxxxxxxxxxxxxx> wrote:
You can try and fudge this in cases where the application cannot possibly trip over the wrong size, but it's tricky to do this without violating the standard, and in an interpreter it's very unlikely to be of any value. Just pick a constant size for integers (4 bytes happens to be a very common one).
So if I write
long long i; char array [100];
for (i = 0; i < 100; ++i) array [i] = i;
the compiler is free to use 1, 2, 3, 4 or any other number of bytes for i, because it doesn't make any difference to the code. The compiler is allowed to cheat, as long as you cannot detect that it cheats.
Yes. The compiler is even free not to use any bytes for i at all and emit a fully initialized array in the object file somewhere, if this is the only piece of code that assigns to 'array'.
Obviously, the burden is on the compiler writer to make sure these optimizations are always safe, but as long as programs have the required semantics, the standard couldn't care less.
S. .
- References:
- C Interpreter and sizeof operator
- From: ozbear
- Re: C Interpreter and sizeof operator
- From: Skarmander
- Re: C Interpreter and sizeof operator
- From: Christian Bau
- C Interpreter and sizeof operator
- Prev by Date: Help wanted on some source codes
- Next by Date: Re: How to redefine arithmetic operators.
- Previous by thread: Re: C Interpreter and sizeof operator
- Next by thread: Re: C Interpreter and sizeof operator
- Index(es):
Relevant Pages
|