Francine.Neary@googlemail.com said:
Quote:
On Aug 31, 12:26 pm, Richard Heathfield <r...@see.sig.invalidwrote:
<snip>
Quote:
Quote:
>Yes, it's to do with clarity. Too many C newbies have this idea that
>C has a "typedef struct" concept. Separating the type creation from
>the synonym creation makes the code clearer.
>
I don't see in what way it makes it clear.
Well, this is obviously a matter of opinion, so I can't prove that it's
clearer with reference to the Standard. But I remember being misled
myself by such conflated constructs when I was learning C, and I have
no desire to inflict my own re-learning curve on other people - so
nowadays I always separate type creation from type renaming.
Quote:
Refraining from using
idiomatic code on the off-chance that a newbie might see it and become
confused is surely going too far.
Um, yes and no. I think it depends very much on the idiom, and how
useful it is. I don't see the ability to create a type during the
process of renaming that very type as being particularly intuitive, and
I prefer to write my code in an intuitive way.
Quote:
(And perhaps the newbie will be
curious rather than confused, and read up to get clear in her mind
what the thing in question is doing.)
Oh, very much so - but I'm afraid that this hypothetical newbie will
have to provoke her curiosity elsewhere. There's plenty of
curiosity-provoking code in the world. I see no reason, however, for me
to add my own contribution to it. I prefer my code to be mind-numbingly
obvious. :-)
<snip>
Quote:
Quote:
>I generally use a trailing underscore nowadays:
>>
>struct node_
>{
> whatever;};
>>
>typedef struct node_ node;
>>
>which doesn't get in the way.
>
It doesn't get in the way, but undeniably it looks ugly.
Ugliosity is in the eye of the beholder.
Quote:
I go for
typedef struct node {
/* stuff */
} node_t;
which isn't beautiful but has a certain logic to it.
It also violates the POSIX Standard, which reserves names ending with _t
for additional type names. Now, strictly speaking, that isn't an issue
here, since POSIX is not topical here - but I thought you might find it
thought-provoking nonetheless. (If you want to find out more about
that, comp.unix.programmer is the place to do so.)
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999