From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cagney To: Nick Duffek Cc: gdb@sources.redhat.com, insight@sources.redhat.com Subject: Re: Register group proposal Date: Thu, 22 Feb 2001 09:12:00 -0000 Message-id: <3A9547ED.E7CFE51C@cygnus.com> References: <3A95369F.98027202@cygnus.com> <200102221645.f1MGjUu03076@rtl.cygnus.com> X-SW-Source: 2001-q1/msg00211.html 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: .h struct ; _method (struct *); enjoy, Andrew