[Bug c/84046] [6/7/8 Regression] global zero-sized objects may have same address

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Jan 27 09:33:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84046

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Zero sized object occupies zero bytes, if you have an array of them,
necessarily all the elements of the array need to have the same address.  While
individual variables could be in theory padded, it would be a waste of address
space for something that doesn't need to occupy any address space. 
Furthermore, in your testcase the objects are common variables, so it is the
linker that allocates them.  If you need unique addresses, just don't use zero
sized objects, if you don't mind them, forcing everyone to have unique
addresses might be a misoptimization for them.


More information about the Gcc-bugs mailing list