Pg. 140 of K&R2 shows an example of mutually referential structure
declarations...
struct t
{
struct s *p;
};
struct s
{
struct t *q;
};
I ran the following test program through my C compiler to see if it
would compile:
#include <stdlib.h>
struct t
{
struct s *p; /* type 'struct s' is not visible here */
};
struct s
{
struct t *q;
};
int main()
{
printf("Hello world\n");
return 0;
}
It compiled and ran without any noticeable problems. I expected it to
complain about the line I've commented above.
How is this valid when the type 'struct s' is not in scope when *p is
declared as a member of the type struct t?
If this is 'valid' please tell me why scopes don't apply here. If this
is 'not valid' please tell me how I can declare mutually referential
struct types.
Thank you
declarations...
struct t
{
struct s *p;
};
struct s
{
struct t *q;
};
I ran the following test program through my C compiler to see if it
would compile:
#include <stdlib.h>
struct t
{
struct s *p; /* type 'struct s' is not visible here */
};
struct s
{
struct t *q;
};
int main()
{
printf("Hello world\n");
return 0;
}
It compiled and ran without any noticeable problems. I expected it to
complain about the line I've commented above.
How is this valid when the type 'struct s' is not in scope when *p is
declared as a member of the type struct t?
If this is 'valid' please tell me why scopes don't apply here. If this
is 'not valid' please tell me how I can declare mutually referential
struct types.
Thank you
Comment