This is the mail archive of the insight@sources.redhat.com mailing list for the Insight project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Register group proposal


Nick Duffek wrote:

> I've noticed, and I've spent time scratching my head over why structs are
> used in various places.

A struct is a poor persons opaque object.

> >Regarding typedefs.  Per my e-mail
> >http://sources.redhat.com/ml/gdb-patches/2001-02/msg00325.html it
> >encouraging a tangled web of includes.
> 
> The example you quoted in that email:
> 
>    Try declaring something like:
> 
>        xyz.h:
>            struct xyz;
>            exter void xyz_foo (struct xyz *self, ...);
> 
>        abc.h:
>            struct xyz;
>            struct abc;
>            extern abc_on_xyz (struct abc *self, struct xyz *on);
> 
>    using typedefs.  It ends up creating include spaghetti :-(
> 
> is very easy to declare using typedefs.  Here's abc.h:

Hmm, I think like MichaelC you may have missed the point.

> is very easy to declare using typedefs.  Here's abc.h:
> 
>    #include "xyz.h"
> 
>    typedef struct {
>      int i;
>    } Abc;
> 
>    extern int abc_on_xyz (Abc *self, Xyz *on);

And that illustrates the problem - why should "abc.h" suck in "xyz.h"
when clients of "abc.h" may not use any of "xyz"'s methods.  If a file
needs to use the method ``xyz_foo()'' then that file should explicitly
include "xyz.h".

It is actually a shame that libremote isn't yet available (yes it is
being worked on ...) Its architecture has everything implemented as
opaque objects.  The header files that define the exported interface are
all fully independant of each other - you don't need to include "abc.h"
to use "xyz.h" and conversely including "abc.h" doesn't quietly suck in
"xyz.h" when its methods are not being used.

> Do we have an official policy prohibiting typedefs in include files?

Using typedefs for things like function declarations? No.

The use of ``typedef struct'' in new interfaces, however, is strongly
discouraged.  You'll notice that all the recently added interfaces have
followed the convention:

	<OBJECT>.h
		struct <OBJECT>;
		<OBJECT>_method (struct <OBJECT> *);

enjoy,
	Andrew


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]