delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/04/20:19:18

Date: Wed, 4 Mar 1998 17:18:35 -0800 (PST)
Message-Id: <199803050118.RAA12570@adit.ap.net>
Mime-Version: 1.0
To: rwh AT worldonline DOT nl, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: struct in struct

At 11:02  3/4/1998 +0100, Reinier Heeres wrote:
>Hi!
>
>How can I define a structure that should look something like this:
>
>typedef struct {
>  int a,b,c;
>  test *children[4];
>  } test;

For self-referential structures, you must use the struct tag. Like this:

typedef struct t {
   int a, b, c;
   struct t *children[4];
} test;

Now
struct t foo;
is the same as
test foo;

For additional obscurity, the `t' above can be changed to `test', so the
struct tag and the typedef name can be the same.

Btw, this would have been better posted to a comp.lang.c group.

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019