This is the mail archive of the mailing list for the GDB 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

> -----Original Message-----
> From: Nick Duffek []
> Sent: Sunday, February 25, 2001 12:52 AM
> To:
> Cc:;
> Subject: RE: Register group proposal
> On 23-Feb-2001, Bernard Dautrevaux wrote:
> >Perhaps for avoiding an unneeded dependency, that would 
> trigger superfluous
> >recompiles of users of "abc.h" that do not need "xyz.h" if "xyz.h" is
> >modified?
> I agree that's a pain.  But prohibiting typedefs only avoids a small
> subset of superfluous recompiles.  For example, changing a 
> single macro in
> gdbarch.h causes a massive rebuild.
> Eventually, GCC probably will support header file compilation, which
> probably will lead to fully-accurate dependency generation.  This will
> eliminate superfluous recompiles.
> In the meantime, the problem diminishes as hardware speedups 
> outpace GCC
> complexity.
> However, humans won't ever get better at writing maintainable code or
> understanding existing code.  Typedefs help us achieve both of those
> goals.

I must say that, although it's a bit shorter, I don't see a real advantage
to define some interface type xxx for

(1) typedef struct { ... } xxx;
    void f(xxx*);


(2) struct xxx;
    void f(struct xxx*);

If you want to get rid of the "struct" in the interface you can go a bit

(3) #ifndef xxx_t
    #define xxx_t struct xxx
    void f(xxx_t*);

You can even go even farther and eliminate the '*' from interfaces:

(4) #ifndef xxx_t_defined
    #define xxx_t_defined
    typedef struct xxx* xxx_t;
    void f(xxx_t);

Personally, I always use approach (2) and never had any problem, but this
may be biased by the fact that most of my own code is written in C++, so the
typedef is implicit and (2) is roughly equivalent to (1), but with the
advantage that xxx is an opaque type, something IMNSHO greatly compensate
for the need to add the "struct" keyword in C.



Bernard Dautrevaux
Microprocess Ingenierie
97 bis, rue de Colombes
Tel:	+33 (0) 1 47 68 80 80
Fax:	+33 (0) 1 47 88 97 85

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