Re: Set with Sort routine

Tech-Archive recommends: Speed Up your PC by fixing your registry



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
.



Relevant Pages

  • Re: Set with Sort routine
    ... typedef struct MyElem ... The only time you need one as part of a typedef like this is when the struct has a pointer to its own type. ... You can't use the typedef name for that, since it hasn't been defined yet, so you have to use the name of the tag, along with the struct keyword. ...
    (microsoft.public.vc.stl)
  • Re: Set with Sort routine
    ... Even in C, you should specify a tag, e.g. ... typedef struct MyElem ... typedef like this is when the struct has a pointer to its own type. ...
    (microsoft.public.vc.stl)
  • Re: Set with Sort routine
    ... typedef struct MyElem ... The only time you need one as part of a typedef like this is when the struct has a pointer to its own type. ... You can't use the typedef name for that, since it hasn't been defined yet, so you have to use the name of the tag, along with the struct keyword. ...
    (microsoft.public.vc.stl)
  • Re: newb help: making sense of typedef enum...
    ... The typedef here is something of a red herring. ... This defines a new type, "enum list_enum", with two enumeration ... struct declaration. ... Of course, you will have to add a tag, just ...
    (comp.lang.c)
  • Re: [PATCH 1/8] sysfs: Implement sysfs tagged directory support.
    ... What this patch does is to add an additional tag field to the ... the same name but internally to sysfs the result is nicer. ... struct sysfs_dirent *cur; ... int error; ...
    (Linux-Kernel)