Reputation: 31577
In a declaration such as int i, v[5], j;
, how will the variables be allocated? Is the compiler allowed to change their order?
Upvotes: 1
Views: 110
Reputation: 13675
Yes, the compiler can (and will) change the order. Ordering is compiler-specific and not specified in the C standards. The C standards don't even specify that a stack should exist.
Upvotes: 2
Reputation: 229128
Yes, the compiler can do whatever it wants, as long as the meaning of the program stays the same. These variables might be optimized out of existence, stored only in a register, reused for other purposes, reordered for alignment requirments.
(note that a compiler cannot reorder variables within a struct)
Upvotes: 3
Reputation: 81349
The compiler is allowed to allocate them pretty much wherever it wants.
Upvotes: 1