Article View: comp.sys.acorn.tech
Article #338Re: C query.
From: Ug!
Date: Thu, 15 Oct 1992 20:49
Date: Thu, 15 Oct 1992 20:49
69 lines
2626 bytes
2626 bytes
Philip R. Banks writes:
> Okay here is a little wee problem I am hoping some C type can answer for
> me. Quickly please, before I take to this compiler with a blunt
> instrument... :)
>
> The problems is thus I have defined a structure like so :-
>
> typedef struct {
> char *name;
> char *comment;
> struct filenode *next;
> struct filenode *prev;
> struct filenode *parent;
> struct filenode *sublist;
> int load;
> int exec;
> int length;
> char flag;
> } filenode;
Hmm. Well, I can see problems already! The type name 'filenode' isn't defined
within the structure definition! It's not defined until the end of the typedef
has been reached.
Try this instead:
struct _filenode
{
char *name,
*comment;
struct _filenode *next,
*prev,
*parent,
*sublist;
int load,
exec,
length;
char flag;
};
typedef struct _filenode filenode, *filenodeptr;
This will define the types correctly (I also tend to define a pointer type:
in this case, 'filenodeptr').
> [more code deleted]
>
> With the last line being the problem one. The compiler gives me the serious
> error number 140 " 'struct filenode' not yet defined - cannot be selected
> from ". Now given that the structure is defined in the *same* file I find
> this a little hard to believe. Also the if statement is in the same scope as
> the declaration of the variable scratch.
See above.
> So can anyone answer what I am doing wrong that the Norcroft compiler is
> soooo helpfully not telling me?
Not the Norcroft compiler, I'm afraid. You would have similar problems with
*any* ANSI C compiler. You simply *cannot* reference a typedef name until
*after* it is defined: this means that referencing the name *during* the
definition will not work.
> I knew there was a good reason for sticking to Assembler. <mumble)
> <mumble).
...or learning the language (whatever it may be) that you are using... ;-}
Ug!
Technical Details
Message-ID:
<1992Oct16.094939.11437@waikato.ac.nz>Path:
arc1-ca.pugleaf.net!sparky!uunet!gumby!wupost!waikato.ac.nz!bwcReferences:
<2qdtw7j025n@khantazi.welly.gen.nz>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!gumby!wupost!waikato.ac.nz!bwc From: bwc@waikato.ac.nz (Ug!) Newsgroups: comp.sys.acorn.tech Subject: Re: C query. Message-ID: <1992Oct16.094939.11437@waikato.ac.nz> Date: 16 Oct 92 09:49:39 +1300 References: <2qdtw7j025n@khantazi.welly.gen.nz> Reply-To: banksie@khantazi.welly.gen.nz Keywords: C, typedef, struct, self Organization: Vooniersity fo Kaiwato Lines: 69