gcc and initialization

Ph. Marek philipp@marek.priv.at
Mon Aug 13 10:10:00 GMT 2007


Hello everybody,

I have some structures in my program, where I could save some space by
overlapping them.

See this example:
	char *yes_no_auto[]= { "auto", "yes", "no" };
	char *yes_no[]= { "yes", "no" };
I know that gcc should fold identical strings in the binary; but if it's
not just strings, but entire structs, this won't help.

Now I wanted to use
	char *yes_no_auto[]= { "auto", "yes", "no" };
	char *yes_no[]=yes_no_auto+1;
but that doesn't work:
	test.c:2: error: invalid initializer

I found that this would work:
	char *yes_no_auto[]= { "auto", "yes", "no" };
	char **yes_no=yes_no_auto+1;

But that won't allow me to use sizeof(yes_no)/sizeof(yes_no[0]) to obtain
the number of elements.

Using "const" doesn't help either.

Any help?


Thank you very much!


Regards,

Phil

-- 
Versioning your /etc, /home or even your whole installation?
             Try fsvs (fsvs.tigris.org)!



More information about the Gcc-help mailing list