mutual reference in structures
Chris Torek
chris at mimsy.UUCP
Thu May 11 21:20:54 AEST 1989
In article <2346 at wheat-chex.ai.mit.edu> jym at wheaties.ai.mit.edu
(Jym Dyer) writes:
>VAX C accepts this (which seems wrong to me):
>
> typedef struct
> {
> struct NODE_T * flink_p;
> struct NODE_T * blink_p;
> char data[512];
> } NODE_T;
This is legal; it is merely stupid. It is the moral equivalent of
typedef struct {
struct never_defined *forw;
struct never_defined *back;
char data[512];
} NODE_T;
Here, you cannot use the pointers `forw' and `back' without first
declaring a structure tag `struct never_defined'. In the quoted
article, you cannot use the pointers `flink_p' and `blink_p' because
there is no `struct NODE_T' (there is only a NODE_T; the typedef
is in a different namespace from structure tags).
>It would be nice if C typedefs knew about themselves ... :
>
> typedef
> {
> NODE_T * flink_p;
> NODE_T * blink_p;
> char data[512];
> } NODE_T;
This would require the ability to `back up', or at least to defer
`thinking about' the declaration. There is nothing in C that now
requires this, so it would be in effect a radical change.
What is so wrong with
typedef struct node_t {
struct node_t *flink_p;
struct node_t *blink_p;
char data[512];
} NODE_T;
anyway?
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list