Dave Korn wrote:
> Dave Korn wrote:
>> Dave Korn wrote:
>>
>>>   ELF GAS/LD seem happy enough when presented with a ".comm foo,0" 
>>> directive,
>>> but PE does rather literally what you asked, and gives you no data object,
>>> leading to i0 in the above being an undefined reference at link time.
>>   After a bit further digging, it turns out that this is because PE uses the
>> same representation for an external symbol as would represent a common of 
>> size
>> 0, so if you define such a common, it magically becomes an undefined external
>> symbol instead!

I don't see what the big deal is here: just allocate one byte to a statically-
allocated zero-length array.

>   And testing it on Linux, I see that the linker goes ahead and assigns zero
> bytes of the common area to i0, then assigns four bytes of common space to i1
> at the same address, so writing to i0[0] aliases and alters i1.  That
> certainly sounds like undefined behaviour to me!

Sure, but in that case it's clearly the user's fault: they're writing beyond
the bounds of an  array.

Andrew.

Reply via email to