typedef in C

Richard O'Keefe ok at edai.UUCP
Thu Mar 8 11:06:06 AEST 1984


     Our news system was pruning old articles, where  an  article  was
deemed  `old'  the  instant it arrived, so I missed the start of this.
If my remark duplicates old information I do apologise.

     The solution to forward pointers in C is essentially the same  as
the  solution  to  forward  pointers  in  Pascal (which does NOT allow
untyped pointers at all, despite the article Re: typedef  in  C).  You
MUST  know  what  a  pointer is pointing to, because there are several
machines around where char* and int* have  DIFFERENT  representations.
What  I  do  is  to  have  somewhere  near  the front of my foo.h file
typedefs like

	typedef struct CELL cellp;

and then put the actual structure or union declarations such as

	typedef struct CELL
	    {
		cellp	next;
		long	junk;
	    } CELL;

anywhere I please.  In PASCAL you would have

	TYPE
	    cellp = ^cell;
	    cell = RECORD
		next: cellp;
		junk: integer;
	    END {cell};

Same difference.  Perfect clarity with no need for hacky #defines.



More information about the Comp.lang.c mailing list