Structure question (problem)
CTD_STUDENT0.
teach0 at whuts.UUCP
Thu May 23 22:59:40 AEST 1985
> Could someone please inform me what the hell I am doing wrong. The
> subject is auto-initialization of structures. Here is a simple program
> that trys to initialize the stucture, and the associated error
> message. If I take one of K&R's examples (pg 124, last half page),
> I get the same error.
> BTW-This is 4.2bsd.
>
> =====
>
> /* Structure test */
>
> #include <stdio.h>
>
>
> main() {
>
> static char *text[] = { "Fred", "Wilma", "Barney", "Betty" };
> struct l {
> int a;
> int b;
> char *c;
> int d;
> } e = { 0, 1, text[0], 4 };
>
> printf("Fred is married to Wilma, Barney to Betty...\n");
>
> }
>
> =====
> % cc t.c
> "t.c", line 14: no automatic aggregate initialization
> "t.c", line 14: warning: illegal combination of pointer and integer, op =
>
Aggregates (arrays, structures, unions) can only be initialized if
they are declared static or external. A simple:
static struct l{ .........
will do.
--
Fred Eng
AT&T Bell Laboratories
More information about the Comp.lang.c
mailing list