Problem initializing a structure
Jeffery Small
jeff at cjsa.WA.COM
Thu Dec 15 04:27:31 AEST 1988
Given the following sample test program:
-- sample program -------------------------------------------------------
#include <stdio.h>
static char *menu[] = { "aaa", "bbb", "ccc", 0 };
typedef struct {
char **mptr;
char *item;
} TEST;
TEST X = { menu, 0 };
main()
{
X.item = menu[0];
(void) printf("\t\t%s %s %s %s\n", *menu, menu[0], menu[1], menu[2]);
return(0);
}
-- end of program -------------------------------------------------------
If you compile and run this program you get the following results:
aaa aaa bbb ccc
as expected, confirming that *menu and menu[?] are pointers to chars.
Now, what I actually want to do is to assign the value to X.item in the
initialization statement rather than the assignment statement. So I make
the following change to the program:
...
TEST X = { menu, *menu };
-- or --
TEST X = { menu, menu[0] };
...
but when I attempt to compile this I get:
> "z.c", line 10: illegal initialization
and lint says:
> (10) illegal initialization
So my question is why doesn't this initialization work and what should I
actually be doing?
I am working on an AT&T 3B1 running OS3.51 (some hybrid of SYSV.2).
Thanks for any help you may be able to offer.
--
Jeffery Small (206) 485-5596 uw-beaver!uw-nsr!uw-warp
C. Jeffery Small and Associates !cjsa!jeff
19112 152nd Ave NE - Woodinville, WA 98072 uunet!nwnexus
More information about the Comp.lang.c
mailing list