Structure pointer question

Andrew Scott andrew at teletron.UUCP
Sat Jun 11 02:42:15 AEST 1988


I have a question regarding pointers to structures and their use in data
structure definitions found in #include files.

Suppose I wish to declare a commonly used data structure, which has as one
of its fields a pointer to a less often used structure.  I wish to define
the structure "templates" in different #include files:

foo.h:					bar.h:

struct bar;				struct bar {
						...
struct foo {				};
	...
	struct bar *f_b;
};

Is it alright to #include "foo.h" and not "bar.h" in a source file if the
fields of "struct bar" are not used?  I would think that it would be fine
as long as pointers to structs are all the same "flavor".  The compiler
I'm using doesn't mind.

I suppose I could #include both if I had to, but I'd rather not because of
modularity reasons.  I'm just wondering what the usual practice is.
-- 
Andrew Scott		andrew at teletron.uucp    - or -
			{att, ubc-cs, watmath, ..}!alberta!teletron!andrew



More information about the Comp.lang.c mailing list