Wouldn't the first struct give an error since it's declaring itself in the middle of it's own declaration?Code:#define MEMBER_SIZE 500 struct table{ double num; struct table *next_table; } struct table member_tables[MEMBER_SIZE];
Wouldn't the first struct give an error since it's declaring itself in the middle of it's own declaration?Code:#define MEMBER_SIZE 500 struct table{ double num; struct table *next_table; } struct table member_tables[MEMBER_SIZE];
this is the typical syntax to write a linked list in C. As for whether or not the compiler should complain, all you're really telling the compiler is that you are declaring another variable, in this case a pointer thats gonna hold the addy of a struct table type. so the short answer is no. I'm sure someone more knowledgeble on here could give you the loooonnnnnger answer.
Last edited by caroundw5h; 03-31-2009 at 10:28 PM. Reason: too tired to think ;(
Warning: Opinions subject to change without notice
The C Library Reference Guide
Understand the fundamentals
Then have some more fun
next_table is a pointer to a table, not a table
╔╗╔══╦╗
║║║╔╗║║
║╚╣╚╝║╚╗
╚═╩══╩═╝
I see what you guys are saying. Because *next_table is creating a pointer of type table, not a new table, it is valid.
caroundw5h, the link you included seems to just be an overview of stdio.h. Do you have a good source regarding linked lists in this manner?
Thanks!
Actually, the posted code is missing a semicolon.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Warning: Opinions subject to change without notice
The C Library Reference Guide
Understand the fundamentals
Then have some more fun