Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: shadypalm88 on December 19, 2004, 09:47 PM

Title: Struct as member of itself?
Post by: shadypalm88 on December 19, 2004, 09:47 PM
I'm trying to get a pointer to a (typedef'd) struct inside itself.  I know that the addrinfo struct does it (albeit not typedef'd), but I'm having trouble doing the same.
Quotetypedef struct _ofdpfolder {
    ucstr_t* name;
    unsigned long numFiles;
    unsigned long numFolders;
    ofdpfile_t* files;
    ofdpfolder_t* folders; // line 21
} ofdpfolder_t;
This is the code I'm trying to use, but gcc is telling me:
Quote from: GNU C Compilerfiles.h:21: error: parse error before "ofdpfolder_t"
Any ideas on how I can get this to work properly?
Title: Re: Struct as member of itself?
Post by: Arta on December 19, 2004, 10:47 PM
change that line to:


struct ofdpfolder_t* folders; // line 21
Title: Re: Struct as member of itself?
Post by: shadypalm88 on December 19, 2004, 11:45 PM
Well, that didn't work, but I think I know what you meant.  Although I thought I had the line as
Quotestruct _ofdpfolder* folders; // line 21
before, and it didn't work, that's how it reads now, and it works fine.  Thanks.
Title: Re: Struct as member of itself?
Post by: Arta on December 20, 2004, 01:03 AM
hmm, yes, that'd be it. I never typedef my structs so I didn't notice :)