This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Initializing structures
- To: Tim Josling <tej at melbpc dot org dot au>
- Subject: Re: Initializing structures
- From: Fergus Henderson <fjh at cs dot mu dot oz dot au>
- Date: Fri, 13 Apr 2001 01:59:51 +1000
- Cc: gcc at gcc dot gnu dot org
- References: <986959978.4125.ezmlm@gcc.gnu.org> <3AD4E5F6.22A29797@melbpc.org.au>
On 12-Apr-2001, Tim Josling <tej@melbpc.org.au> wrote:
> In COBOL, you can specify initial values at any level. Translated
> to C this would look like this.
>
> struct mystruct {
> int a;
> int b;
> int c;
> ];
>
> struct mystruct XXX = "AAABBBCCC";
>
> In my dealings with tree.c I have tried to implement this in a
> straighforward way by setting a char[] initial value to the
> structure but the code generation appears to just ignore this.
...
> Any better ideas?
How about using a union to declare XXX?
struct mystruct {
int a;
int b;
int c;
};
union {
char c[sizeof(struct mystruct)];
struct mystruct s;
} XXX = { "AAABBBCCC"; };
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.