questionnaire

Tom Stockfisch tps at chem.ucsd.edu
Sat Jan 13 13:30:27 AEST 1990


In article <1990Jan12.022039.15799 at ux1.cso.uiuc.edu> phil at ux1.cso.uiuc.edu (Phil Howard KA9WGN) writes:
>I would like to find out from some different people what kinds of decisions
>you typically make, and how you might make them regarding:
>1.  Whether or not to use "typedef" for a "struct"

I define *all* structs as

	typedef struct FOO {...} FOO;

Typedefs and struct tags belong to different identifier overload classes,
so the same name may be used for both.  Now you can say either
	
	struct FOO	bar;

or just

	FOO	bar;

>    a.  how do you deal with the case of two different struct types
>        having pointers to the other type?

This method automatically takes care of this:

	struct FOO2;

	typedef struct FOO {
		struct FOO	*next, *previous;
		...
		struct FOO2	*buddy;
	}	FOO;

	typedef struct FOO2 {
		struct FOO2	*next, *previous;
		...
		struct FOO	*buddy;
	}	FOO2;

>2.  When you decide to separate structures into header files

If you have two different source files which use the same struct, the struct
definition better be in a header file which is included by both.  Otherwise,
I probably would keep it in the same file.
-- 

|| Tom Stockfisch, UCSD Chemistry	tps at chem.ucsd.edu



More information about the Comp.lang.c mailing list