Re: [dwm] C coding question

From: Sylvain Bertrand <sylvain.bertrand_AT_gmail.com>
Date: Wed, 10 Oct 2007 18:32:11 +0200

2007/10/10, Anselm R. Garbe <arg_AT_suckless.org>:
> On Tue, Oct 02, 2007 at 05:49:02PM +0200, Enno Gottox Boland wrote:
> > That brings me to another style question:
> >
> > For me, it is easier to read and to understand when I write linked
> > structures that way:
> >
> > typedef struct Abc {
> > ...
> > struct Abc *next;
> > } Abc;
> > ...
> > Abc abc;
> >
> > Is there a reason not to do so?
>
> I though a while about this, and yes I thing k
>
> [...]
> Client *next;
> Client *prev;
> Client *snext;
> [...]
>
> looks less clunky than
>
> [...]
> struct Client *next;
> struct Client *prev;
> struct Client *snext;
> [...]
>
> But I agree with you in the general case.
>
> Regards,
> Anselm
>
What about that one? :)
typedef struct client_t client_t;

[...]
   client_t *next;
   client_t *prev;
   client_t *snext;
[...]

cheers,

  Sylvain
> >
> > 2007/10/2, Juanval <juanval_AT_gmail.com>:
> > > On 10/2/07, Anselm R. Garbe <arg_AT_suckless.org> wrote:
> > > > On Tue, Oct 02, 2007 at 04:54:21PM +0200, Juanval wrote:
> > > > > Hi there,
> > > > >
> > > > > I'm revamping my C coding skills (in my university they just teach C++
> > > > > and Java, and I had to learn proper C on my own :-S), and I'm reading
> > > > > the dwm 4.3 as an exercise, as it seems a very elegantly written piece
> > > > > of code.
> > > > >
> > > > > And I was wondering why is Client defined this way:
> > > > > ------------------------------------
> > > > > typedef struct Client Client;
> > > > > struct Client {
> > > > > [...]
> > > > > };
> > > > > ------------------------------------
> > > > > Instead of doing it the same way as, for example, DC:
> > > > > ------------------------------------
> > > > > typedef struct {
> > > > > [...]
> > > > > } DC;
> > > > > ------------------------------------
> > > > >
> > > > > Are there any functional differences I am missing? To me, they look
> > > > > like they do basically the same thing... :-S
> > > >
> > > > Yes, the first one is a forward declaration of the type Client
> > > > (which is defined as struct Client) because this is used within
> > > > the Client struct itself.
> > > >
> > > > In the second struct DC is not used within the struct itself, so
> > > > a forward declaration would be pointless.
> > >
> > > Aaaah, ok, that explains everything. Thanks a lot.
> > >
> > > And thanks yiyus for the c-faq link. I'll definitely spend lots of
> > > time on that page :)
> > >
> > >
> >
> >
> > --
> > http://www.gnuffy.org - Real Community Distro
> > http://www.gnuffy.org/index.php/GnuEm - Gnuffy on Ipaq (Codename Peggy)
> >
>
> --
> Anselm R. Garbe >< http://www.suckless.org/ >< GPG key: 0D73F361
>
>
Received on Wed Oct 10 2007 - 18:32:12 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 14:58:57 UTC