
Structue within a structure
Joseph a crit dans le message ...
Quote:
>My program consists of about 15 seperate files. I have a structure
>declared before main:
>typedef struct form {int a; int b; } form;
This is a type declaration;
Quote:
>form *FORM1;
This is a definition.
Quote:
>Then, in an include that the outside files use:
>struct form {int a; int b;};
This is a structure declaration.
Quote:
>extern form; (it may be extern FORM1, I can't remember, but it works
>:) )
This is a structure declaration.
Quote:
>My current problem is that I want to add a struct to the struct:
>typedef struct inside {char b[4]; int a;} inside;
>which I define above the form structure definition. I then alter form
>to read:
>typedef struct form {int a; int b; inside INSIDE1;} form;
>and do the same in the include file.
Why do you have 2 declarations? Headers files are here to avoid that.
Quote:
>This works in the first file, but in the include file, the compiler
>complains that it has run into type inside, when it was expecting a
>closing bracket.
This is really unclear. What sould be done is to put the declarations in the
headers, and the definitions in the C files. Just define things before you
use them. Add a guard in the header.
/* header.h */
#ifndef HEADER_H
#define HEADER_H
typedef struct
{
char b[4];
int a;
Quote:
} inside_t;
typedef struct
{
int a;
int b;
inside_t INSIDE1;
Quote:
} form_t;
#endif /* HEADER_H */
/* source.c */
#include "header.h"
int main (void)
{
form_t form;
return 0;
Quote:
}
--
-hs- Tabs out, spaces in.
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://www.dinkum.com/htm_cl
FAQ de FCLC : http://www.isty-info.uvsq.fr/~rumeau/fclc
--