views:

119

answers:

1

I have made a structure for ints and pointers etc. as might be used in LISP.

A pointer is at least 8-byte aligned so tag=0. An integer is 29 bits and has a tag of 1. Other types have different tag values.

struct Atom{
  union{
    Pair              *pair;
    struct{
      unsigned        tag     :3;
      union{
        int           val     :29;
        char          ch;
        struct{
          int         mant    :21;
          Exp         exp     :8;
        };
      };
    };
  };
};

I would like to initialise them differently.

For pointers:

Atom aPair = {{.pair=0}}; // works

or

Atom aPair = {{0}}; //works

This works because, I assume, GCC assumes that I want to initialise the first member of the union.

I'd also like to initialise an integer - something like this:

Atom anInt={{ {.tag=1,{.val=0} } }};

I know this is not standard C, but is this possible at all with anonymous structures in GCC?

+1  A: 

It is a known bug.

KennyTM
Thank you. I did not consider that the compiler might be at fault.
philcolbourn