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

Re: [MiNT] anonymous structs and C99



Did you tried giving a name to that union ? like:

struct xxx
{
  int x;
  int y;
  union myUnionName
  {
    char* pointer1;
    int* pointer2;
  };
} a;

Greetings/Pozdrawiam,
M.Buras



2009/5/24 Miro Kropacek <miro.kropacek@gmail.com>:
> Okay, this isn't exactly Atari/MiNT related question but I came to this
> while coding on Atari :) And since there is plenty of skilled people...
>
> This:
>
> struct xxx
> {
>   int x;
>   int y;
>   union
>   {
>     char* pointer1;
>     int* pointer2;
>   };
> } a;
>
> compiles just fine with gcc. But as soon as I switch to -std=c99 mode,
> compiler complains: error: ‘struct xxx’ has no member named ‘pointer1’. From
> what I know, C99 standard says anonymous structs should be allocated on
> stack but I don't see how it relates to this problem...
>
> Is there any workaround for this? I like this anonymous union because it
> makes access to various pointers easier (I don't have to use void* and then
> cast it) and it has always the same size (char*, int*, short* -- everything
> pointers).
>
> Any hint appreciated :)
>
> --
> MiKRO / Mystic Bytes
> http://mikro.atari.org
>