defining big types on avr-gcc

Massimiliano Cialdi massimiliano.cialdi@powersoft.it
Wed Aug 4 09:52:00 GMT 2010


Il giorno mer, 04/08/2010 alle 10.35 +0100, Andrew Haley ha scritto:
> > 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?
offsetof is defined as follows:
#define offsetof(st, m) \
    ((size_t) ( (char *)&((st *)(0))->m - (char *)0 ))

this gives me the warning:
'integer overflow in expression'
when I call:
offsetof(big_dummy_t, singledata);

for that reason I start to try in different way.

do you mean __builtin_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.
how?

thanks



More information about the Gcc-help mailing list