defining big types on avr-gcc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I use avr-gcc 4.4.4:

Using built-in specs.
Target: avr
Configured with: ../gcc-4.4.4/configure --target=avr
--enable-languages=c,c++ --disable-nls --disable-libssp --with-dwarf2
--prefix=/usr/local/cross-gcc-avr-4.4.4 --disable-threads --with-gnu-as
--with-gnu-ld
Thread model: single
gcc version 4.4.4 (GCC)



and my target is an ATMega32

I tried to define a type (only define, without allocate any variable):



typedef struct dummy
{
  uint8_t data[9000];
} dummy_t;

typedef struct big_dummy
{
  dummy_t bigdata[4];
  dummy_t singledata;
} big_dummy_t;



I never allocate any big_dummy_t object. I use big_dummy_t only as
placeholder (I use offsetof() macro), only to calculate offsets of
object placed into a big extern serial flash memory.

I get the error from gcc:

error: size of array 'bigdata' is too large

it is 36000 bytes, bigger than 32KB.

after many tests I found a possible solution:

typedef struct dummy
{
  uint8_t data[9000];
} dummy_t;

typedef struct big_dummy
{
  union
  {
    dummy_t bigdata[0];
    struct
    {
      dummy_t bigdata0;
      dummy_t bigdata1;
      dummy_t bigdata2;
      dummy_t bigdata3;
    };
  };
  dummy_t singledata;
} big_dummy_t;

now if I want the offset of a field I can do as follows:

uint16_t p = (uint16_t)&(((big_dummy_t*)0)->bigdata[3]);

This works, but if I wand offset of singledata:

uint16_t p = (uint16_t)&(((big_dummy_t*)0)->singledata);

I get a warning: 'integer overflow in expression'

but if I change in this way:
big_dummy_t *p = (big_dummy_t*)0;
uint16_t p = (uint16_t)&(p->singledata);

I get NO warning!!!

This looks incredible to me. I wonder why.
Is it a bug?

thanks





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux