Re: [dwm] C coding question

From: Anselm R. Garbe <>
Date: Tue, 2 Oct 2007 17:14:41 +0200

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.

> Sorry if this question seems offtopic in this list. It's just that the
> K&R book (I'm re-reading it now...) doesn't seem to say anything about
> this kind of things, and I couldn't think of a better group of C
> coders to ask this.

The alternative would be to use 'struct Client' everywhere
instead of simply Client, but that is harder to read ;)


 Anselm R. Garbe >< >< GPG key: 0D73F361
Received on Tue Oct 02 2007 - 17:14:41 UTC

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