This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Initializing structures


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]