I'm new to C (and Usenet) and have been using the dreaded Schildt's Complete
C Reference. I appreciate this may not have been the best idea, so no need
to point this out!
On page 546 there is a mailing list program with a struct defined thus:
struct address {
char name[30];
char street[40];
char city[20];
char state[3];
char zip[11];
struct address *next;
struct address *prior;
};
The program is to demonstrate a doubly linked list, and works fine when
compiled. I tried playing with it to tidy things up, and tried to make a
typedef from the struct:
typedef struct {
char name[30];
char street[40];
char city[20];
char state[3];
char zip[11];
address *next;
address *prior;
} address;
This caused a compile time error. I assume this is because 'address' is
referenced in the struct before the typedef is completed. I got round the
problem by doing this:
typedef struct address {
char name[30];
char street[40];
char city[20];
char state[3];
char zip[11];
struct address *next;
struct address *prior;
} address;
....which solves the problem. Is this the correct syntax or am I introducing
undefined behaviour? Mr Schildt's book isn't much help!
Thanks in advance.
--
Neil McPhail