Re: Set with Sort routine
- From: "Doug Harrison [MVP]" <dsh@xxxxxxxx>
- Date: Wed, 28 Jun 2006 14:45:44 -0500
On Wed, 28 Jun 2006 11:58:13 -0400, Pete Becker <petebecker@xxxxxxx> wrote:
Doug Harrison [MVP] wrote:
On Tue, 27 Jun 2006 16:57:48 -0400, Pete Becker <petebecker@xxxxxxx> wrote:
I do not use tags automatically, and would not recommend doing so. That
just clutters the code. If they're needed, add 'em. Or get a better
compiler.
I dunno, I always viewed giving the type a real name as the primary thing,
while having to write "typedef" and duplicate the type name at the end of
the struct declaration were the things that added clutter.
Exactly my point:
typedef struct name
{
// whatever
} name;
is cluttered and, as you point out later, misleading.
Yes, having to wrap the struct declaration with typedef in order to refer
to the struct by name does make it cluttered. I don't see how it's
misleading, though. In my last message, I showed that omission of the tag
can result in nonsensical error messages when using your proverbial "better
compiler", which does address the problem for which you invoked it; that
is, it uses the typedef name in error messages instead of "<unnamed>" or
some invented and more unique name.
It was
unfortunate that C pretty much required it for pleasantness purposes.
As I said before: C does not require a tag when the struct is part of a
typedef.
I was talking about wrapping a struct declaration with typedef (or more
generally, typedef'ing a struct). It was unfortunate C required this
clutter in order to "just use" the name of the type.
As for the tag rule, I'm well aware it. I haven't said that tags are
"required", nor have I implied it.
There's another reason to always use struct tags; they make it possible to
use forward declarations.
Listing situations where tags are useful is not an argument for always
using tags. Use tags when you need them.
I did more than merely "list a situation". I demonstrated how applying your
clutter principle can lead to confusing error messages when using your
proverbial "better compiler"; it was also a counter-example to your claim
concerning "the only time you need one...". Then there's the problem of
talking about types, e.g. does "the structure named X" mean "struct X", or
could it also apply to an unnamed struct typedef'd as "X"? It's a lot
simpler if you make the tag and typedef names the same.
--
Doug Harrison
Visual C++ MVP
.
- Follow-Ups:
- Re: Set with Sort routine
- From: Pete Becker
- Re: Set with Sort routine
- References:
- Set with Sort routine
- From: Bruce Chastain
- Re: Set with Sort routine
- From: Doug Harrison [MVP]
- Re: Set with Sort routine
- From: Pete Becker
- Re: Set with Sort routine
- From: Doug Harrison [MVP]
- Re: Set with Sort routine
- From: Pete Becker
- Re: Set with Sort routine
- From: Doug Harrison [MVP]
- Re: Set with Sort routine
- From: Pete Becker
- Set with Sort routine
- Prev by Date: Re: Set with Sort routine
- Next by Date: Re: Set with Sort routine
- Previous by thread: Re: Set with Sort routine
- Next by thread: Re: Set with Sort routine
- Index(es):
Relevant Pages
|