forward references in typedefs

Walter Murray walter at hpclwjm.HP.COM
Fri Jul 21 05:03:16 AEST 1989


George M. Jones writes:

>   typedef struct one
>     {
>       two_t *foo;
>     } one_t;
>   typedef struct two
>     {
>       one_t *bar;
>     } two_t;

This code is incorrect by the syntax rules of ANSI C.  The identifier
'two_t' by itself is not a valid type-specifier in the declaration
of 'foo', unless it has previously been defined as a typedef name.

This is probably what you want:

  typedef struct one one_t;
  typedef struct two two_t;
  struct one
    {
      two_t *foo;
    } ;
  struct two
    {
      one_t *bar;
    } ;

Walter Murray
---
Not speaking for Hewlett-Packard or X3J11
-------------



More information about the Comp.lang.c mailing list