This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: defining big types on avr-gcc
On 08/04/2010 10:15 AM, Massimiliano Cialdi wrote:
> Il giorno mer, 04/08/2010 alle 10.06 +0100, Andrew Haley ha scritto:
>
>>> So why if I write:
>>> big_dummy_t *p = (big_dummy_t*)0;
>>> uint16_t p = (uint16_t)&(p->singledata);
>>>
>>> I get NO warning?
>>
>> Because the first is constant folded, the second isn't. Not that it
>> matters, because your program is undefined anyway, since you're
>> dereferencing a null pointer.
> I never read or write data poined by p. I only use it to calculate
> offset of fields inside it.
It's still pretty dubious. Why not use offsetof?
> I could write:
> uint16_t p = (uint16_t)((char *)&(p->singledata) - (char*)0);
You could, but that's undefined too: you can only subtract pointers
that are part of the same array.
But I don't see the point of this anyway. You can easily use
arithmetic to calculate the offsets in your external flash memory.
Andrew.