Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Error in operator: add beer


devel / comp.lang.c / Re: Why does C allow structs to have a tag?

SubjectAuthor
* Why does C allow structs to have a tag?James Harris
+* Re: Why does C allow structs to have a tag?David Brown
|`* Re: Why does C allow structs to have a tag?Thiago Adams
| `- Re: Why does C allow structs to have a tag?David Brown
+- Re: Why does C allow structs to have a tag?Öö Tiib
+* Re: Why does C allow structs to have a tag?Bart
|+* Re: Why does C allow structs to have a tag?Kaz Kylheku
||+- Re: Why does C allow structs to have a tag?Bart
||`* Re: Why does C allow structs to have a tag?Manfred
|| `* Re: Why does C allow structs to have a tag?David Brown
||  `* Re: Why does C allow structs to have a tag?Bart
||   +- Re: Why does C allow structs to have a tag?Richard Harnden
||   +* Re: Why does C allow structs to have a tag?Keith Thompson
||   |+* Re: Why does C allow structs to have a tag?Bart
||   ||+- Re: Why does C allow structs to have a tag?Keith Thompson
||   ||`* Re: Why does C allow structs to have a tag?James Harris
||   || `- Re: Why does C allow structs to have a tag?Bart
||   |`* Re: Why does C allow structs to have a tag?Manfred
||   | `* Re: Why does C allow structs to have a tag?Keith Thompson
||   |  `* Re: Why does C allow structs to have a tag?Bart
||   |   +* Re: Why does C allow structs to have a tag?David Brown
||   |   |`- Re: Why does C allow structs to have a tag?Bart
||   |   `* Re: Why does C allow structs to have a tag?Keith Thompson
||   |    `- Re: Why does C allow structs to have a tag?Malcolm McLean
||   `* Re: Why does C allow structs to have a tag?David Brown
||    `* Re: Why does C allow structs to have a tag?Bart
||     +* Re: Why does C allow structs to have a tag?David Brown
||     |`* Re: Why does C allow structs to have a tag?Bart
||     | `* Re: Why does C allow structs to have a tag?Malcolm McLean
||     |  `* Re: Why does C allow structs to have a tag?Bart
||     |   `* Re: Why does C allow structs to have a tag?Kaz Kylheku
||     |    `* Re: Why does C allow structs to have a tag?Bart
||     |     +- Re: Why does C allow structs to have a tag?James Harris
||     |     `* Re: Why does C allow structs to have a tag?Kaz Kylheku
||     |      `* Re: Why does C allow structs to have a tag?Bart
||     |       `* Re: Why does C allow structs to have a tag?Keith Thompson
||     |        `* Re: Why does C allow structs to have a tag?Bart
||     |         `- Re: Why does C allow structs to have a tag?Keith Thompson
||     `* Re: Why does C allow structs to have a tag?James Harris
||      `- Re: Why does C allow structs to have a tag?Bart
|`- Re: Why does C allow structs to have a tag?Keith Thompson
+* Re: Why does C allow structs to have a tag?Kaz Kylheku
|`* Re: Why does C allow structs to have a tag?Bart
| `- Re: Why does C allow structs to have a tag?James Harris
+- Re: Why does C allow structs to have a tag?James Kuyper
+* Re: Why does C allow structs to have a tag?Richard Damon
|`- Re: Why does C allow structs to have a tag?James Harris
+* Re: Why does C allow structs to have a tag?Joe Pfeiffer
|`* Re: Why does C allow structs to have a tag?Malcolm McLean
| +* Re: Why does C allow structs to have a tag?Guillaume
| |+* Re: Why does C allow structs to have a tag?Kaz Kylheku
| ||`* Re: Why does C allow structs to have a tag?Bart
| || `* Re: Why does C allow structs to have a tag?Kaz Kylheku
| ||  `* Re: Why does C allow structs to have a tag?Bart
| ||   `- Re: Why does C allow structs to have a tag?Keith Thompson
| |`* Re: Why does C allow structs to have a tag?James Kuyper
| | `* Re: Why does C allow structs to have a tag?Bart
| |  `* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   +* Re: Why does C allow structs to have a tag?Bart
| |   |`* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   | `* Re: Why does C allow structs to have a tag?Bart
| |   |  `* Re: Why does C allow structs to have a tag?David Brown
| |   |   `* Re: Why does C allow structs to have a tag?Bart
| |   |    +* Re: Why does C allow structs to have a tag?David Brown
| |   |    |`* Re: Why does C allow structs to have a tag?Bart
| |   |    | `* Re: Why does C allow structs to have a tag?David Brown
| |   |    |  +* Re: Why does C allow structs to have a tag?Manfred
| |   |    |  |`- Re: Why does C allow structs to have a tag?David Brown
| |   |    |  +- Re: Why does C allow structs to have a tag?Bart
| |   |    |  `* Re: Why does C allow structs to have a tag?Bart
| |   |    |   +- Re: Why does C allow structs to have a tag?David Brown
| |   |    |   `* Re: Why does C allow structs to have a tag?Keith Thompson
| |   |    |    +* Re: Why does C allow structs to have a tag?Guillaume
| |   |    |    |+* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   |    |    ||`- Re: Why does C allow structs to have a tag?Keith Thompson
| |   |    |    |+- Re: Why does C allow structs to have a tag?Keith Thompson
| |   |    |    |+- Re: Why does C allow structs to have a tag?Keith Thompson
| |   |    |    |`- Re: Why does C allow structs to have a tag?David Brown
| |   |    |    `* Re: Why does C allow structs to have a tag?Bart
| |   |    |     `* Re: Why does C allow structs to have a tag?Keith Thompson
| |   |    |      `* Re: Why does C allow structs to have a tag?Bart
| |   |    |       +* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   |    |       |`* Re: Why does C allow structs to have a tag?Ben Bacarisse
| |   |    |       | `* Re: Why does C allow structs to have a tag?Bart
| |   |    |       |  `* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   |    |       |   `* Re: Why does C allow structs to have a tag?Bart
| |   |    |       |    +* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   |    |       |    |`* Re: Why does C allow structs to have a tag?Bart
| |   |    |       |    | `- Re: Why does C allow structs to have a tag?Keith Thompson
| |   |    |       |    `- Re: Why does C allow structs to have a tag?Keith Thompson
| |   |    |       `- Re: Why does C allow structs to have a tag?David Brown
| |   |    `* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   |     `* Re: Why does C allow structs to have a tag?Bart
| |   |      `* Re: Why does C allow structs to have a tag?Kaz Kylheku
| |   |       `- Re: Why does C allow structs to have a tag?Bart
| |   `* Re: Why does C allow structs to have a tag?Bart
| |    +- Re: Why does C allow structs to have a tag?Keith Thompson
| |    `- Re: Why does C allow structs to have a tag?Kaz Kylheku
| +* Re: Why does C allow structs to have a tag?Joe Pfeiffer
| |`- Re: Why does C allow structs to have a tag?Kaz Kylheku
| `- Re: Why does C allow structs to have a tag?Richard Damon
+* Re: Why does C allow structs to have a tag?John Bode
+- Re: Why does C allow structs to have a tag?Siri Cruise
`* Re: Why does C allow structs to have a tag?Andrey Tarasevich

Pages:12345678910111213141516
Why does C allow structs to have a tag?

<s9iea5$n5c$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16852&group=comp.lang.c#16852

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.ha...@gmail.com (James Harris)
Newsgroups: comp.lang.c
Subject: Why does C allow structs to have a tag?
Date: Sun, 6 Jun 2021 13:16:05 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <s9iea5$n5c$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 6 Jun 2021 12:16:05 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d4c910d9b5fc6f9ba6c952bc096a4ccd";
logging-data="23724"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+iKBp1RphX9XUfd3zIAboj67likK0letI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.8.1
Cancel-Lock: sha1:WtwxQPWR4e04IVGSHFj/Zu9GmcI=
Content-Language: en-US
X-Mozilla-News-Host: snews://news.eternal-september.org:563
 by: James Harris - Sun, 6 Jun 2021 12:16 UTC

Does C, as a language, need to allow its structs to have tags?

AIUI a fragment such as "struct A {....};" reserves no storage but
declares a template which can be used later, e.g. to declare a variable
as in

struct A var;

to declare a parameter as in

void f(struct A parm) {....}

to effect a cast as in

(struct A *) p

etc but in all such cases struct A is being used as a type. And there is
a more general feature for that in typedef.

So could C's struct tags be omitted from the language? If not, what does
a struct tag add? Is it something to do with forward declarations or
syntactic consistency with union tags, etc?

--
James Harris

Re: Why does C allow structs to have a tag?

<s9iih0$iu7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16854&group=comp.lang.c#16854

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Sun, 6 Jun 2021 15:27:59 +0200
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <s9iih0$iu7$1@dont-email.me>
References: <s9iea5$n5c$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 6 Jun 2021 13:28:00 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2f41c68a2c2dfb607575f829d8bbee22";
logging-data="19399"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191Ajra9saqm7NYwv/p+3aUhoBIOH464ik="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:LHQa+m9ihHusdQA1CsiBBsYF7aA=
In-Reply-To: <s9iea5$n5c$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Sun, 6 Jun 2021 13:27 UTC

On 06/06/2021 14:16, James Harris wrote:
> Does C, as a language, need to allow its structs to have tags?
>
> AIUI a fragment such as "struct A {....};" reserves no storage but
> declares a template which can be used later, e.g. to declare a variable
> as in
>
>   struct A var;
>
> to declare a parameter as in
>
>   void f(struct A parm) {....}
>
> to effect a cast as in
>
>   (struct A *) p
>
> etc but in all such cases struct A is being used as a type. And there is
> a more general feature for that in typedef.
>
> So could C's struct tags be omitted from the language? If not, what does
> a struct tag add? Is it something to do with forward declarations or
> syntactic consistency with union tags, etc?
>

Struct tags are not required if you have a typedef:

typedef struct { int a; int b; } A;

They are also not needed if you only refer to the struct once :

struct { int a; int b; } a;

But in general if you have two "struct" declarations, these define
different types - even if they contain the same members. So if you want
to use the type more than once, you need to give it a name - either
using a tag or by making it part of a typedef.

Forward declarations require a tag - there is no way to avoid that.
Beyond that, I think you can skip tags and stick to typedef if you prefer.

(Some people feel it is better to refer to the type as "struct A" rather
than a typedef "A", others prefer to use typdefs and avoid the "struct"
part.)

Re: Why does C allow structs to have a tag?

<c8ff18b1-f902-4a69-9457-10bdc3af6a45n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16856&group=comp.lang.c#16856

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:a703:: with SMTP id q3mr12499782qke.269.1622986477715; Sun, 06 Jun 2021 06:34:37 -0700 (PDT)
X-Received: by 2002:a05:620a:b09:: with SMTP id t9mr12893115qkg.17.1622986477485; Sun, 06 Jun 2021 06:34:37 -0700 (PDT)
Path: i2pn2.org!i2pn.org!news.swapon.de!news.uzoreto.com!tr3.eu1.usenetexpress.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 6 Jun 2021 06:34:37 -0700 (PDT)
In-Reply-To: <s9iea5$n5c$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=94.246.251.86; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 94.246.251.86
References: <s9iea5$n5c$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c8ff18b1-f902-4a69-9457-10bdc3af6a45n@googlegroups.com>
Subject: Re: Why does C allow structs to have a tag?
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Sun, 06 Jun 2021 13:34:37 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 27
 by: Öö Tiib - Sun, 6 Jun 2021 13:34 UTC

On Sunday, 6 June 2021 at 15:16:17 UTC+3, James Harris wrote:
> Does C, as a language, need to allow its structs to have tags?
>
> AIUI a fragment such as "struct A {....};" reserves no storage but
> declares a template which can be used later, e.g. to declare a variable
> as in
>
> struct A var;
>
> to declare a parameter as in
>
> void f(struct A parm) {....}
>
> to effect a cast as in
>
> (struct A *) p
>
> etc but in all such cases struct A is being used as a type. And there is
> a more general feature for that in typedef.
>
> So could C's struct tags be omitted from the language? If not, what does
> a struct tag add? Is it something to do with forward declarations or
> syntactic consistency with union tags, etc?

Not from C language. C language removes only features that no one
uses and even those very slowly. The "struct A" will be there forever as
it is quite popular. But from your code go ahead, David Brown
explained how.

Re: Why does C allow structs to have a tag?

<0x4vI.109969$Ye1.83143@fx01.ams4>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16857&group=comp.lang.c#16857

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx01.ams4.POSTED!not-for-mail
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me>
From: bc...@freeuk.com (Bart)
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.0
MIME-Version: 1.0
In-Reply-To: <s9iea5$n5c$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 8bit
X-Antivirus: AVG (VPS 210605-4, 05/06/2021), Outbound message
X-Antivirus-Status: Clean
Lines: 66
Message-ID: <0x4vI.109969$Ye1.83143@fx01.ams4>
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Sun, 06 Jun 2021 13:59:24 UTC
Organization: virginmedia.com
Date: Sun, 6 Jun 2021 14:59:23 +0100
X-Received-Bytes: 2572
 by: Bart - Sun, 6 Jun 2021 13:59 UTC

On 06/06/2021 13:16, James Harris wrote:
> Does C, as a language, need to allow its structs to have tags?
>
> AIUI a fragment such as "struct A {....};" reserves no storage but
> declares a template which can be used later, e.g. to declare a variable
> as in
>
>  struct A var;
>
> to declare a parameter as in
>
>  void f(struct A parm) {....}
>
> to effect a cast as in
>
>  (struct A *) p
>
> etc but in all such cases struct A is being used as a type. And there is
> a more general feature for that in typedef.
>
> So could C's struct tags be omitted from the language? If not, what does
> a struct tag add? Is it something to do with forward declarations or
> syntactic consistency with union tags, etc?
>
>

They add nothing at all to the language. Other languages don't need
them. Even C++ I think is moving away from them.

It's just another quirk among many (you probably know that tags have
their own namespace too).

However, as C works at the minute, tags are needed for self-referential
structs, or with cyclic references. This won't work, even if you try and
have a forward declaration for Node:

typedef struct {
int data;
Node* next;
} Node;

You have to use:

typedef struct Nodetag{
int data;
struct Nodetag* next;
} Node;

Of course, as a long-standing feature of C, many will claim it is
invaluable. For example that using:

struct Nodetag x;

is clearer than:

Node x;

because you know that you're dealing with a struct. My view is that a
feature that allows:

struct Nodetag Nodetag;

is not one you'd want one to emulate.

Re: Why does C allow structs to have a tag?

<20210606074535.550@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16861&group=comp.lang.c#16861

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 563-365-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Sun, 6 Jun 2021 14:51:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <20210606074535.550@kylheku.com>
References: <s9iea5$n5c$1@dont-email.me>
Injection-Date: Sun, 6 Jun 2021 14:51:59 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="de541172929387eba4f17011be4f46f6";
logging-data="17241"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XtWpbrnyJvpmS7I5iTOS0zF/dJ/w8Jr4="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:NlxOM+3bzzS45yoVn3HVvags9pU=
 by: Kaz Kylheku - Sun, 6 Jun 2021 14:51 UTC

On 2021-06-06, James Harris <james.harris.1@gmail.com> wrote:
> etc but in all such cases struct A is being used as a type. And there is
> a more general feature for that in typedef.

typedef is general, but a general what?

It's purely a type aliasing mechanism for giving names to existing
types. It doesn't define new types.

> So could C's struct tags be omitted from the language? If not, what does
> a struct tag add? Is it something to do with forward declarations or
> syntactic consistency with union tags, etc?

The tag is essential in the C design for self-referential
structures:

struct node {
struct node *next;
void *datum;
};

typedef cannot solve this because

typedef struct {
node *next; // error: typedef does not exist yet!
void *datum;
} node;

The struct specifier is what introduces a type; typedef just introduces
the name "node" into the scope which refers to that type.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Why does C allow structs to have a tag?

<20210606075302.305@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16862&group=comp.lang.c#16862

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 563-365-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Sun, 6 Jun 2021 15:05:05 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <20210606075302.305@kylheku.com>
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
Injection-Date: Sun, 6 Jun 2021 15:05:05 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="de541172929387eba4f17011be4f46f6";
logging-data="17241"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UoY5iLYwEp7AJIDJ/kgo8q9ZN1wPaM4c="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:yB4mlzN7IIZzGytsd94VxDhkcf0=
 by: Kaz Kylheku - Sun, 6 Jun 2021 15:05 UTC

On 2021-06-06, Bart <bc@freeuk.com> wrote:
> You have to use:
>
> typedef struct Nodetag{

There is no requirement that the tag and type name must be distinct
since they are in separate namespaces.

> int data;
> struct Nodetag* next;
> } Node;

It will work wit a forward declaration too, but that of course
still requires the tag appearing in two places:

typedef struct Nodetag Node;

struct Nodetag {
Nodetag *next;
};

> because you know that you're dealing with a struct. My view is that a
> feature that allows:
>
> struct Nodetag Nodetag;
>
> is not one you'd want one to emulate.

On the contrary, type names should be in a separate namespace, so that
an object of type foo can naturally be named foo when you need it:

node = new node;
other_node = new node;

Only crap languages reduce everything to one namespace.

C does not escape this disparagement. Though it provides that
struct/enum tag namespace, it's for those kinds of types only, and you
have to reference it explicitly.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Why does C allow structs to have a tag?

<1v5vI.20225$St1.18675@fx12.ams4>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16863&group=comp.lang.c#16863

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx12.ams4.POSTED!not-for-mail
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <20210606074535.550@kylheku.com>
From: bc...@freeuk.com (Bart)
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.0
MIME-Version: 1.0
In-Reply-To: <20210606074535.550@kylheku.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 7bit
X-Antivirus: AVG (VPS 210606-4, 06/06/2021), Outbound message
X-Antivirus-Status: Clean
Lines: 60
Message-ID: <1v5vI.20225$St1.18675@fx12.ams4>
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Sun, 06 Jun 2021 15:05:33 UTC
Organization: virginmedia.com
Date: Sun, 6 Jun 2021 16:05:33 +0100
X-Received-Bytes: 2846
 by: Bart - Sun, 6 Jun 2021 15:05 UTC

On 06/06/2021 15:51, Kaz Kylheku wrote:
> On 2021-06-06, James Harris <james.harris.1@gmail.com> wrote:
>> etc but in all such cases struct A is being used as a type. And there is
>> a more general feature for that in typedef.
>
> typedef is general, but a general what?
>
> It's purely a type aliasing mechanism for giving names to existing
> types. It doesn't define new types.
>
>> So could C's struct tags be omitted from the language? If not, what does
>> a struct tag add? Is it something to do with forward declarations or
>> syntactic consistency with union tags, etc?
>
> The tag is essential in the C design for self-referential
> structures:
>
> struct node {
> struct node *next;
> void *datum;
> };
>
> typedef cannot solve this because
>
> typedef struct {
> node *next; // error: typedef does not exist yet!
> void *datum;
> } node;
>
> The struct specifier is what introduces a type; typedef just introduces
> the name "node" into the scope which refers to that type.

It's only essential because C has decided that's how it has to work.

Your example works with C++; how does that manage it?

C could have done it with a forward declaration of 'node', but:

typedef node;

is not valid; you need to give a type, and that type then counts as
either a separate or duplicate struct to the one defined later. Or you
use a tag for that forward, empty struct declaration, so you're back to
square one.

It's just fortuitous that the tag is placed just before {...} instead of
just after, otherwise you'd have the same problem with tags.

A minor tweak of syntax, such as:

typedef newtype = oldtype; // with oldtype name-less

instead of:

typedef oldtype newtype; // with oldtype/newtype wrapped around
// each other for complex types

would have done it.

Re: Why does C allow structs to have a tag?

<LS5vI.20226$St1.4018@fx12.ams4>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16864&group=comp.lang.c#16864

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx12.ams4.POSTED!not-for-mail
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
<20210606075302.305@kylheku.com>
From: bc...@freeuk.com (Bart)
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.0
MIME-Version: 1.0
In-Reply-To: <20210606075302.305@kylheku.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 7bit
X-Antivirus: AVG (VPS 210606-4, 06/06/2021), Outbound message
X-Antivirus-Status: Clean
Lines: 62
Message-ID: <LS5vI.20226$St1.4018@fx12.ams4>
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Sun, 06 Jun 2021 15:30:51 UTC
Organization: virginmedia.com
Date: Sun, 6 Jun 2021 16:30:51 +0100
X-Received-Bytes: 2670
 by: Bart - Sun, 6 Jun 2021 15:30 UTC

On 06/06/2021 16:05, Kaz Kylheku wrote:
> On 2021-06-06, Bart <bc@freeuk.com> wrote:
>> You have to use:
>>
>> typedef struct Nodetag{
>
>
> There is no requirement that the tag and type name must be distinct
> since they are in separate namespaces.
>
>> int data;
>> struct Nodetag* next;
>> } Node;
>
> It will work wit a forward declaration too, but that of course
> still requires the tag appearing in two places:
>
> typedef struct Nodetag Node;
>
> struct Nodetag {
> Nodetag *next;
> };
>
>
>> because you know that you're dealing with a struct. My view is that a
>> feature that allows:
>>
>> struct Nodetag Nodetag;
>>
>> is not one you'd want one to emulate.
>
> On the contrary, type names should be in a separate namespace, so that
> an object of type foo can naturally be named foo when you need it:

Why would you want that? Case-sensitive languages already allow that
anyway if you're really stuck for inventing meaningful new identifiers.

Foo foo;

> node = new node;
> other_node = new node;

It took me a while to figure out what this is supposed to mean.

So 'node' following 'new' is a type; but the other node is a variable
name? What about:

node node;

> Only crap languages reduce everything to one namespace.

Namespaces are used where they are genuinely useful, for example to
disambiguate A.F from B.F. It's not so you can have F meaning two or
more different things within the same scope. This is an example from C
(one of 8 case variations of the three As):

A:; struct A A; goto A;

Really handy when half the keys don't work on your keyboard!

Re: Why does C allow structs to have a tag?

<s9ipsb$4nn$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16865&group=comp.lang.c#16865

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.ha...@gmail.com (James Harris)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Sun, 6 Jun 2021 16:33:31 +0100
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <s9ipsb$4nn$1@dont-email.me>
References: <s9iea5$n5c$1@dont-email.me> <20210606074535.550@kylheku.com>
<1v5vI.20225$St1.18675@fx12.ams4>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 6 Jun 2021 15:33:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d4c910d9b5fc6f9ba6c952bc096a4ccd";
logging-data="4855"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/73tX3YfCbXQXVvEK3iiNcN/2cpSZh1jw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.8.1
Cancel-Lock: sha1:MntmGaQrbUhBbDNtlsNnYzcDqHM=
In-Reply-To: <1v5vI.20225$St1.18675@fx12.ams4>
Content-Language: en-US
 by: James Harris - Sun, 6 Jun 2021 15:33 UTC

On 06/06/2021 16:05, Bart wrote:
> On 06/06/2021 15:51, Kaz Kylheku wrote:

....

>> The tag is essential in the C design for self-referential
>> structures:

Agreed with those who have mentioned that. I am not sure whether C still
needs to prohibit forward references. They were once needed for
single-pass compilation, I would think, but that era is long past.

> It's just fortuitous that the tag is placed just before {...} instead of
> just after, otherwise you'd have the same problem with tags.

Far from fortuitous it's more likely to be good design. With

struct A {....} B;

isn't it true that either A or B can be omitted, and that A will be the
struct tag and B will be an identifier which is being declared as of the
specified struct type? And it fits with C's ordering of

type identfier

That's a really quite subtle and consistent design feature, ISTM.

>
> A minor tweak of syntax, such as:
>
>   typedef newtype = oldtype;   // with oldtype name-less
>
> instead of:
>
>   typedef oldtype newtype;     // with oldtype/newtype wrapped around
>                                // each other for complex types
>
> would have done it.

Yes, I prefer your 'tweaked' syntax for a programming language (though
am not suggesting it for C), just without the semicolon, as in

typedef newtypename = oldtypespec

--
James Harris

Re: Why does C allow structs to have a tag?

<s9iurd$d7c$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16870&group=comp.lang.c#16870

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!ElFVPqY+TvFDjG0suNPrQQ.user.gioia.aioe.org.POSTED!not-for-mail
From: non...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Sun, 6 Jun 2021 18:58:23 +0200
Organization: Aioe.org NNTP Server
Lines: 31
Message-ID: <s9iurd$d7c$1@gioia.aioe.org>
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
<20210606075302.305@kylheku.com>
NNTP-Posting-Host: ElFVPqY+TvFDjG0suNPrQQ.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Manfred - Sun, 6 Jun 2021 16:58 UTC

On 6/6/2021 5:05 PM, Kaz Kylheku wrote:
> On 2021-06-06, Bart <bc@freeuk.com> wrote:
>> You have to use:
>>
>> typedef struct Nodetag{
>
>
> There is no requirement that the tag and type name must be distinct
> since they are in separate namespaces.
>
>> int data;
>> struct Nodetag* next;
>> } Node;
>
> It will work wit a forward declaration too, but that of course
> still requires the tag appearing in two places:
>
> typedef struct Nodetag Node;
>
> struct Nodetag {
> Nodetag *next; // error: unknown type name ‘Nodetag’
> };
>
>

typedef struct Nodetag Node;

struct Nodetag {
int data;
Node *next;
};

Re: Why does C allow structs to have a tag?

<s9j3kk$b23$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16872&group=comp.lang.c#16872

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Sun, 6 Jun 2021 14:20:03 -0400
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <s9j3kk$b23$1@dont-email.me>
References: <s9iea5$n5c$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 6 Jun 2021 18:20:04 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="cf1dfec1a14cbe25ab0c15669493f612";
logging-data="11331"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lfet9e5HWkvy957r1HEM1L6lu9Xv6Pm4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.8.1
Cancel-Lock: sha1:zuEIj7f5cv4bc8uRDqZDMxrWe/U=
In-Reply-To: <s9iea5$n5c$1@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Sun, 6 Jun 2021 18:20 UTC

On 6/6/21 8:16 AM, James Harris wrote:
> Does C, as a language, need to allow its structs to have tags?
>
> AIUI a fragment such as "struct A {....};" reserves no storage but
> declares a template which can be used later, e.g. to declare a variable
> as in
>
> struct A var;
>
> to declare a parameter as in
>
> void f(struct A parm) {....}
>
> to effect a cast as in
>
> (struct A *) p
>
> etc but in all such cases struct A is being used as a type. And there is
> a more general feature for that in typedef.
>
> So could C's struct tags be omitted from the language? If not, what does
> a struct tag add? Is it something to do with forward declarations or
> syntactic consistency with union tags, etc?

C++ dropped the requirement for tags, so it's clearly not necessary.
Except when hidden by the use of a typedef, C's rule guarantees that
every specification of a struct type includes the "struct" keyword.
Because of that rule, struct tags have their own separate name space,
which allows you to use the same identifier for a struct type and for a
given object of that type. That's not possible in C++, where they are in
the same name space. Note: a "name space" is a concept that exists in
both of those languages, though it's less important in C++. A "name
space" is not directly related to the C++ namespace keyword.
Strougstrop obviously thought that the C++ rules were an improvement. C
is more constrained than C++ by the need to maintain backwards
compatibility, which would be broken by adoption of the C++ rules.

Re: Why does C allow structs to have a tag?

<l_8vI.9103$Vh1.1344@fx21.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16873&group=comp.lang.c#16873

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx21.iad.POSTED!not-for-mail
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me>
From: Rich...@Damon-Family.org (Richard Damon)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0)
Gecko/20100101 Thunderbird/78.11.0
MIME-Version: 1.0
In-Reply-To: <s9iea5$n5c$1@dont-email.me>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 8bit
Lines: 44
Message-ID: <l_8vI.9103$Vh1.1344@fx21.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sun, 6 Jun 2021 15:03:44 -0400
X-Received-Bytes: 2472
 by: Richard Damon - Sun, 6 Jun 2021 19:03 UTC

On 6/6/21 8:16 AM, James Harris wrote:
> Does C, as a language, need to allow its structs to have tags?
>
> AIUI a fragment such as "struct A {....};" reserves no storage but
> declares a template which can be used later, e.g. to declare a variable
> as in
>
>   struct A var;
>
> to declare a parameter as in
>
>   void f(struct A parm) {....}
>
> to effect a cast as in
>
>   (struct A *) p
>
> etc but in all such cases struct A is being used as a type. And there is
> a more general feature for that in typedef.
>
> So could C's struct tags be omitted from the language? If not, what does
> a struct tag add? Is it something to do with forward declarations or
> syntactic consistency with union tags, etc?
>
>

The biggest need is for referencing a struct whose definition hasn't
been given, especially as a pointer type.

You can say 'struct A' to reference that type without ever having seen
the actual definition of what that structure looks like.

You can NOT do this with a typedef. You CAN say
typedef struct A Astruct; to make Astruct a typedef for that unknown
struct type, but even that requires the struct tag to be specified, so
it can possible be linked later when the struct is actually defined.

Except by using this sort of tag, there is no way in C to say that a
name is to some type that may be defined later.

I suppose C could be extended to allow a statement like typedef A; to
define that A was a type, that later might get connected to some defined
type. This would allow you to define pointers to that type.

Re: Why does C allow structs to have a tag?

<s9j6mv$v9r$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16874&group=comp.lang.c#16874

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Sun, 6 Jun 2021 21:12:31 +0200
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <s9j6mv$v9r$1@dont-email.me>
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
<20210606075302.305@kylheku.com> <s9iurd$d7c$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 6 Jun 2021 19:12:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2f41c68a2c2dfb607575f829d8bbee22";
logging-data="32059"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jVgmskgr8GJczUuCyxtB7gW/YTvAlrsU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:wd6t5/cxsBxPKw2mcW3iuhrpSok=
In-Reply-To: <s9iurd$d7c$1@gioia.aioe.org>
Content-Language: en-GB
 by: David Brown - Sun, 6 Jun 2021 19:12 UTC

On 06/06/2021 18:58, Manfred wrote:
> On 6/6/2021 5:05 PM, Kaz Kylheku wrote:
>> On 2021-06-06, Bart <bc@freeuk.com> wrote:
>>> You have to use:
>>>
>>>     typedef struct Nodetag{
>>
>>
>> There is no requirement that the tag and type name must be distinct
>> since they are in separate namespaces.
>>
>>>       int data;
>>>       struct Nodetag* next;
>>>     } Node;
>>
>> It will work wit a forward declaration too, but that of course
>> still requires the tag appearing in two places:
>>
>>    typedef struct Nodetag Node;
>>
>>    struct Nodetag {
>>      Nodetag *next; //  error: unknown type name ‘Nodetag’
>>    };
>>
>>
>
> typedef struct Nodetag Node;
>
> struct Nodetag {
>   int data;
>   Node *next;
> };

Or even:

typedef struct Node Node;

struct Node {
int data;
Node *next;
};

There's no need for an extra name here.

Re: Why does C allow structs to have a tag?

<3R9vI.65671$jM2.54125@fx02.ams4>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16875&group=comp.lang.c#16875

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx02.ams4.POSTED!not-for-mail
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
<20210606075302.305@kylheku.com> <s9iurd$d7c$1@gioia.aioe.org>
<s9j6mv$v9r$1@dont-email.me>
From: bc...@freeuk.com (Bart)
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.0
MIME-Version: 1.0
In-Reply-To: <s9j6mv$v9r$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 8bit
X-Antivirus: AVG (VPS 210606-6, 06/06/2021), Outbound message
X-Antivirus-Status: Clean
Lines: 46
Message-ID: <3R9vI.65671$jM2.54125@fx02.ams4>
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Sun, 06 Jun 2021 20:02:07 UTC
Organization: virginmedia.com
Date: Sun, 6 Jun 2021 21:02:06 +0100
X-Received-Bytes: 1945
 by: Bart - Sun, 6 Jun 2021 20:02 UTC

On 06/06/2021 20:12, David Brown wrote:
> On 06/06/2021 18:58, Manfred wrote:
>> On 6/6/2021 5:05 PM, Kaz Kylheku wrote:

>>>    typedef struct Nodetag Node;
>>>
>>>    struct Nodetag {
>>>      Nodetag *next; //  error: unknown type name ‘Nodetag’
>>>    };
>>>
>>>
>>
>> typedef struct Nodetag Node;
>>
>> struct Nodetag {
>>   int data;
>>   Node *next;
>> };
>
>
> Or even:
>
> typedef struct Node Node;
>
> struct Node {
> int data;
> Node *next;
> };
>
> There's no need for an extra name here.

Unless you want to avoid any confusion. Since you can come across this:

Node* A;
struct Node* B;

Does one of those lines have a 'struct' missing, or does the other have
a 'struct' that shouldn't be there?

The eye picks up such inconsistencies; it creates a distraction.

Allowing two ways of denoting the same user-type is also sloppy.

Re: Why does C allow structs to have a tag?

<s9javu$tig$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16876&group=comp.lang.c#16876

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: richard....@gmail.com (Richard Harnden)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Sun, 6 Jun 2021 21:25:31 +0100
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <s9javu$tig$1@dont-email.me>
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
<20210606075302.305@kylheku.com> <s9iurd$d7c$1@gioia.aioe.org>
<s9j6mv$v9r$1@dont-email.me> <3R9vI.65671$jM2.54125@fx02.ams4>
Reply-To: nospam.harnden@gmail.com
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 6 Jun 2021 20:25:34 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7016f84b0ec6aad64f335181de88a3be";
logging-data="30288"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19A8kxD2gw/cRNakvR6IQyetENigErYVCw="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0)
Gecko/20100101 Thunderbird/78.11.0
Cancel-Lock: sha1:fo8mlx7/Lg7mLFHBFIpRs2GMYPc=
In-Reply-To: <3R9vI.65671$jM2.54125@fx02.ams4>
Content-Language: en-GB
 by: Richard Harnden - Sun, 6 Jun 2021 20:25 UTC

On 06/06/2021 21:02, Bart wrote:
> On 06/06/2021 20:12, David Brown wrote:
>> On 06/06/2021 18:58, Manfred wrote:
>>> On 6/6/2021 5:05 PM, Kaz Kylheku wrote:
>
>
>>>>     typedef struct Nodetag Node;
>>>>
>>>>     struct Nodetag {
>>>>       Nodetag *next; //  error: unknown type name ‘Nodetag’
>>>>     };
>>>>
>>>>
>>>
>>> typedef struct Nodetag Node;
>>>
>>> struct Nodetag {
>>>    int data;
>>>    Node *next;
>>> };
>>
>>
>> Or even:
>>
>> typedef struct Node Node;
>>
>> struct Node {
>>    int data;
>>    Node *next;
>> };
>>
>> There's no need for an extra name here.
>
> Unless you want to avoid any confusion. Since you can come across this:
>
> Node* A;
> struct Node* B;
>
> Does one of those lines have a 'struct' missing, or does the other have
> a 'struct' that shouldn't be there?
>
> The eye picks up such inconsistencies; it creates a distraction.
>
> Allowing two ways of denoting the same user-type is also sloppy.

That's why the "_t" suffix in "typedef struct foo foo_t" is popular.

Personally, I'm happy to loose the typedef and say struct foo when
that's what I mean. It's not that much extra typing.

Re: Why does C allow structs to have a tag?

<87zgw2ve3n.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16877&group=comp.lang.c#16877

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Sun, 06 Jun 2021 15:10:36 -0700
Organization: None to speak of
Lines: 47
Message-ID: <87zgw2ve3n.fsf@nosuchdomain.example.com>
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="da0ef0006e1a2be3c584df7adb5e6866";
logging-data="27278"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+JlC2Zoa06dsUrG8Rp2zk6"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)
Cancel-Lock: sha1:KsR1nYGZkPAxrmQJ2/9e3+WIUVo=
sha1:e/LWvom4QwVflqCdRignLGY2Gq8=
 by: Keith Thompson - Sun, 6 Jun 2021 22:10 UTC

Bart <bc@freeuk.com> writes:
> On 06/06/2021 13:16, James Harris wrote:
>> Does C, as a language, need to allow its structs to have tags?
>>
>> AIUI a fragment such as "struct A {....};" reserves no storage but
>> declares a template which can be used later, e.g. to declare a
>> variable as in
>>
>>  struct A var;
>>
>> to declare a parameter as in
>>
>>  void f(struct A parm) {....}
>>
>> to effect a cast as in
>>
>>  (struct A *) p
>>
>> etc but in all such cases struct A is being used as a type. And
>> there is a more general feature for that in typedef.
>>
>> So could C's struct tags be omitted from the language? If not, what
>> does a struct tag add? Is it something to do with forward
>> declarations or syntactic consistency with union tags, etc?
>
> They add nothing at all to the language. Other languages don't need
> them. Even C++ I think is moving away from them.

No, it isn't.

In C, you can define a structure type as
struct foo { /* members /* };

where "foo" is the tag. The name of the resulting type is "struct foo".
You can optionally add a typedef if you prefer to refer to it as "foo"

In C++, the same type, defined with the same syntax, can be referred to
either as "struct foo" or as "foo"; the latter is more common. The
identifier "foo" is still the struct tag. C++ has worked this way for
decades; it's not "moving away" from anything.

[...]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

Re: Why does C allow structs to have a tag?

<87v96qvdyx.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16878&group=comp.lang.c#16878

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Sun, 06 Jun 2021 15:13:26 -0700
Organization: None to speak of
Lines: 61
Message-ID: <87v96qvdyx.fsf@nosuchdomain.example.com>
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
<20210606075302.305@kylheku.com> <s9iurd$d7c$1@gioia.aioe.org>
<s9j6mv$v9r$1@dont-email.me> <3R9vI.65671$jM2.54125@fx02.ams4>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="da0ef0006e1a2be3c584df7adb5e6866";
logging-data="27278"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19MCtUtbv+FliO7igbqhhMQ"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)
Cancel-Lock: sha1:GLy36KSkXLP6A0Ej5Df4evzXOX4=
sha1:NP2smYvBY7VEZNLLhieIo24usVU=
 by: Keith Thompson - Sun, 6 Jun 2021 22:13 UTC

Bart <bc@freeuk.com> writes:
> On 06/06/2021 20:12, David Brown wrote:
>> On 06/06/2021 18:58, Manfred wrote:
>>> On 6/6/2021 5:05 PM, Kaz Kylheku wrote:
>>>>    typedef struct Nodetag Node;
>>>>
>>>>    struct Nodetag {
>>>>      Nodetag *next; //  error: unknown type name ‘Nodetag’
>>>>    };
>>>>
>>>>
>>>
>>> typedef struct Nodetag Node;
>>>
>>> struct Nodetag {
>>>   int data;
>>>   Node *next;
>>> };
>>
>>
>> Or even:
>>
>> typedef struct Node Node;
>>
>> struct Node {
>> int data;
>> Node *next;
>> };
>>
>> There's no need for an extra name here.
>
> Unless you want to avoid any confusion. Since you can come across this:
>
> Node* A;
> struct Node* B;
>
> Does one of those lines have a 'struct' missing, or does the other
> have a 'struct' that shouldn't be there?
>
> The eye picks up such inconsistencies; it creates a distraction.
>
> Allowing two ways of denoting the same user-type is also sloppy.

Which is a great argument for not bothering with the typedef:

struct Node {
int data;
struct Node *next;
};

struct Node obj;
struct Node *ptr;
// ...

(Bart will argue that having to type "struct" again is a heavy burden.
I will not respond.)

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

Re: Why does C allow structs to have a tag?

<DncvI.6679$NL.2399@fx18.ams4>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16879&group=comp.lang.c#16879

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!fdc2.netnews.com!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx18.ams4.POSTED!not-for-mail
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
<20210606075302.305@kylheku.com> <s9iurd$d7c$1@gioia.aioe.org>
<s9j6mv$v9r$1@dont-email.me> <3R9vI.65671$jM2.54125@fx02.ams4>
<87v96qvdyx.fsf@nosuchdomain.example.com>
From: bc...@freeuk.com (Bart)
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.0
MIME-Version: 1.0
In-Reply-To: <87v96qvdyx.fsf@nosuchdomain.example.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 8bit
X-Antivirus: AVG (VPS 210606-6, 06/06/2021), Outbound message
X-Antivirus-Status: Clean
Lines: 76
Message-ID: <DncvI.6679$NL.2399@fx18.ams4>
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Sun, 06 Jun 2021 22:55:31 UTC
Organization: virginmedia.com
Date: Sun, 6 Jun 2021 23:55:30 +0100
X-Received-Bytes: 3165
 by: Bart - Sun, 6 Jun 2021 22:55 UTC

On 06/06/2021 23:13, Keith Thompson wrote:
> Bart <bc@freeuk.com> writes:
>> On 06/06/2021 20:12, David Brown wrote:
>>> On 06/06/2021 18:58, Manfred wrote:
>>>> On 6/6/2021 5:05 PM, Kaz Kylheku wrote:
>>>>>    typedef struct Nodetag Node;
>>>>>
>>>>>    struct Nodetag {
>>>>>      Nodetag *next; //  error: unknown type name ‘Nodetag’
>>>>>    };
>>>>>
>>>>>
>>>>
>>>> typedef struct Nodetag Node;
>>>>
>>>> struct Nodetag {
>>>>   int data;
>>>>   Node *next;
>>>> };
>>>
>>>
>>> Or even:
>>>
>>> typedef struct Node Node;
>>>
>>> struct Node {
>>> int data;
>>> Node *next;
>>> };
>>>
>>> There's no need for an extra name here.
>>
>> Unless you want to avoid any confusion. Since you can come across this:
>>
>> Node* A;
>> struct Node* B;
>>
>> Does one of those lines have a 'struct' missing, or does the other
>> have a 'struct' that shouldn't be there?
>>
>> The eye picks up such inconsistencies; it creates a distraction.
>>
>> Allowing two ways of denoting the same user-type is also sloppy.
>
> Which is a great argument for not bothering with the typedef:
>
> struct Node {
> int data;
> struct Node *next;
> };
>
> struct Node obj;
> struct Node *ptr;
> // ...
>
> (Bart will argue that having to type "struct" again is a heavy burden.
> I will not respond.)
>

There is NO argument. Every other language including C++ sees separate
tag names as pointless. C++ can't completely get rid of them, so still
allows 'struct tag{}' or 'struct tag x' for compatibility with C code,
although 'struct tag{}' here creates a typedef 'tag' too.

C++ actually allows this:

typedef struct T {int x,y;} U;

so that you can use T, struct T or U (but not struct U). So C
compatibility has given it /three/ ways of denoting the same user-type!

I declare such a struct like this (in one language):

type T = struct (int x,y)

It declares exactly one user type, denoted always as just 'T'.

Re: Why does C allow structs to have a tag?

<87eedev8xc.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16880&group=comp.lang.c#16880

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Sun, 06 Jun 2021 17:02:23 -0700
Organization: None to speak of
Lines: 29
Message-ID: <87eedev8xc.fsf@nosuchdomain.example.com>
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
<20210606075302.305@kylheku.com> <s9iurd$d7c$1@gioia.aioe.org>
<s9j6mv$v9r$1@dont-email.me> <3R9vI.65671$jM2.54125@fx02.ams4>
<87v96qvdyx.fsf@nosuchdomain.example.com>
<DncvI.6679$NL.2399@fx18.ams4>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="da0ef0006e1a2be3c584df7adb5e6866";
logging-data="9411"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rrH7STTqbDdXx4o+66uqr"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)
Cancel-Lock: sha1:vrNlutO0TEIukEh36AoxMfZY0Eg=
sha1:LHTgdVjUEHW2u/MK+X+310bsJXY=
 by: Keith Thompson - Mon, 7 Jun 2021 00:02 UTC

Bart <bc@freeuk.com> writes:
[...]
> There is NO argument. Every other language including C++ sees separate
> tag names as pointless. C++ can't completely get rid of them, so still
> allows 'struct tag{}' or 'struct tag x' for compatibility with C code,
> although 'struct tag{}' here creates a typedef 'tag' too.
[...]

No, that's not a typedef. It's just the name of the type. C++ does
have typedefs, but as in C they require the "typedef" keyword.

In C, you can write "typedef struct foo { ... } foo;". Then "foo" is a
typedef name, and an alias for the type that is also named "struct foo".

In C++, you can write "struct foo { ... };", and "struct foo" and
"foo" are both names for the type. Neither of them is a typedef.
The name "foo" acts much like the typedef name in C. (There might
be subtle differences; I'm not sure.)

And something I just noticed: C++ doesn't use the term "tag". "foo" is
a "class name".

The distinction is not deeply significant. I'm just like to get the
terminology right.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

Re: Why does C allow structs to have a tag?

<s9kfn9$plt$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16881&group=comp.lang.c#16881

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Mon, 7 Jun 2021 08:52:24 +0200
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <s9kfn9$plt$1@dont-email.me>
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
<20210606075302.305@kylheku.com> <s9iurd$d7c$1@gioia.aioe.org>
<s9j6mv$v9r$1@dont-email.me> <3R9vI.65671$jM2.54125@fx02.ams4>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 7 Jun 2021 06:52:25 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1c012dee47c94b53fe51858691c79ef8";
logging-data="26301"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+g8YAhBjs2l/lcOi6S7zfBaJjcMJ3K+ZI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:wcatOKDNNb2/HcOseSCy2AFArv0=
In-Reply-To: <3R9vI.65671$jM2.54125@fx02.ams4>
Content-Language: en-GB
 by: David Brown - Mon, 7 Jun 2021 06:52 UTC

On 06/06/2021 22:02, Bart wrote:
> On 06/06/2021 20:12, David Brown wrote:
>> On 06/06/2021 18:58, Manfred wrote:
>>> On 6/6/2021 5:05 PM, Kaz Kylheku wrote:
>
>
>>>>     typedef struct Nodetag Node;
>>>>
>>>>     struct Nodetag {
>>>>       Nodetag *next; //  error: unknown type name ‘Nodetag’
>>>>     };
>>>>
>>>>
>>>
>>> typedef struct Nodetag Node;
>>>
>>> struct Nodetag {
>>>    int data;
>>>    Node *next;
>>> };
>>
>>
>> Or even:
>>
>> typedef struct Node Node;
>>
>> struct Node {
>>    int data;
>>    Node *next;
>> };
>>
>> There's no need for an extra name here.
>
> Unless you want to avoid any confusion. Since you can come across this:
>
> Node* A;
> struct Node* B;
>
> Does one of those lines have a 'struct' missing, or does the other have
> a 'struct' that shouldn't be there?
>
> The eye picks up such inconsistencies; it creates a distraction.
>
> Allowing two ways of denoting the same user-type is also sloppy.
>

What you call "sloppy", others might call "flexible". You are, IIRC, a
fan of case-insensitive languages. Are they sloppy for letting you
write "foo" and "Foo" to mean the same thing? Or are you just engaging
in your favourite hobby - taking something that other people see as a
convenient way to write clearer code and using it for yet another
meaningless rant against C?

I agree that it is good to be consistent when you write your code, and I
would expect a programmer to choose either "struct Node" /or/ "Node",
and use it consistently. Generally, you'd only find the typedef at all
if the programmer intends to use "Node" consistently.

So there is no confusion that I can see.

(On the other hand, I think code like "struct Node Node;" is a lot more
likely to cause confusion.)

Re: Why does C allow structs to have a tag?

<ocmvI.707714$7Kb.680010@fx37.ams4>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16882&group=comp.lang.c#16882

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.usenet.farm!feed.usenet.farm!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx37.ams4.POSTED!not-for-mail
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
<20210606075302.305@kylheku.com> <s9iurd$d7c$1@gioia.aioe.org>
<s9j6mv$v9r$1@dont-email.me> <3R9vI.65671$jM2.54125@fx02.ams4>
<s9kfn9$plt$1@dont-email.me>
From: bc...@freeuk.com (Bart)
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.0
MIME-Version: 1.0
In-Reply-To: <s9kfn9$plt$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 7bit
X-Antivirus: AVG (VPS 210607-0, 07/06/2021), Outbound message
X-Antivirus-Status: Clean
Lines: 71
Message-ID: <ocmvI.707714$7Kb.680010@fx37.ams4>
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Mon, 07 Jun 2021 10:06:12 UTC
Organization: virginmedia.com
Date: Mon, 7 Jun 2021 11:06:10 +0100
X-Received-Bytes: 3514
 by: Bart - Mon, 7 Jun 2021 10:06 UTC

On 07/06/2021 07:52, David Brown wrote:
> On 06/06/2021 22:02, Bart wrote:

>> Unless you want to avoid any confusion. Since you can come across this:
>>
>> Node* A;
>> struct Node* B;
>>
>> Does one of those lines have a 'struct' missing, or does the other have
>> a 'struct' that shouldn't be there?
>>
>> The eye picks up such inconsistencies; it creates a distraction.
>>
>> Allowing two ways of denoting the same user-type is also sloppy.
>>
>
> What you call "sloppy", others might call "flexible". You are, IIRC, a
> fan of case-insensitive languages. Are they sloppy for letting you
> write "foo" and "Foo" to mean the same thing?

You mean in the same way that "bart", "Bart" or "BART" all refer to me?

Or the fact that if I say them out loud, they all sound identical too?

> Or are you just engaging
> in your favourite hobby - taking something that other people see as a
> convenient way to write clearer code and using it for yet another
> meaningless rant against C?

No. For me case sensitivity means code that ISN'T clearer because people
exploit that subtle difference in case between otherwise identical
names: to use them for different purposes not just within the same
scope, but across a program, where you have to keep doing a double-take.

Here are some wonderful examples from sqlite3.c:

Action action
affinity Affinity
B b
bIn bin
BusyHandler busyHandler
Clsid clsid CLSID
DbPage dbpage
debuginfo DebugInfo
dwContextHelpId dwContextHelpID
dwFlags dwflags
Edx eDx
errmsg errMsg
hwndActive hWndActive
message Message MESSAGE
nExt next Next
szPMA szPma
WalIndexHdr walIndexHdr

> I agree that it is good to be consistent when you write your code, and I
> would expect a programmer to choose either "struct Node" /or/ "Node",
> and use it consistently. Generally, you'd only find the typedef at all
> if the programmer intends to use "Node" consistently.

My manually written C code only ever defines structs as part of a
typedef. And only uses tags when necessary to define the struct. It is
then subsequently referred to by the typedef name.

My automatically generated C code does the opposite; never uses typedefs
for structs (because there, who cares?).

But in any other language, we just wouldn't be discussing this at all.
You create a new type, be it a struct or anything else, and it's called
T. End of story.

Re: Why does C allow structs to have a tag?

<s9kvni$ah$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16883&group=comp.lang.c#16883

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Why does C allow structs to have a tag?
Date: Mon, 7 Jun 2021 13:25:38 +0200
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <s9kvni$ah$1@dont-email.me>
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
<20210606075302.305@kylheku.com> <s9iurd$d7c$1@gioia.aioe.org>
<s9j6mv$v9r$1@dont-email.me> <3R9vI.65671$jM2.54125@fx02.ams4>
<s9kfn9$plt$1@dont-email.me> <ocmvI.707714$7Kb.680010@fx37.ams4>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 7 Jun 2021 11:25:38 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1c012dee47c94b53fe51858691c79ef8";
logging-data="337"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+AXMHKuUuR+zTbqWTmlho50Okaw7rMX34="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:/PArDkz1ErDWXVXfDm03ytgxC/k=
In-Reply-To: <ocmvI.707714$7Kb.680010@fx37.ams4>
Content-Language: en-GB
 by: David Brown - Mon, 7 Jun 2021 11:25 UTC

On 07/06/2021 12:06, Bart wrote:
> On 07/06/2021 07:52, David Brown wrote:
>> On 06/06/2021 22:02, Bart wrote:
>
>>> Unless you want to avoid any confusion. Since you can come across this:
>>>
>>> Node* A;
>>> struct Node* B;
>>>
>>> Does one of those lines have a 'struct' missing, or does the other have
>>> a 'struct' that shouldn't be there?
>>>
>>> The eye picks up such inconsistencies; it creates a distraction.
>>>
>>> Allowing two ways of denoting the same user-type is also sloppy.
>>>
>>
>> What you call "sloppy", others might call "flexible".  You are, IIRC, a
>> fan of case-insensitive languages.  Are they sloppy for letting you
>> write "foo" and "Foo" to mean the same thing?
>
> You mean in the same way that "bart", "Bart" or "BART" all refer to me?
>
> Or the fact that if I say them out loud, they all sound identical too?

So you are happy with multiple ways of writing "bart" or "BART" that
look very different, and would immediately be viewed as different
identifiers and therefore different meanings to people familiar with
case-sensitive programming languages. Yet you would be upset with two
versions of writing the same type in C that are really quite obvious to
C programmers - and where any mistakes (in real code) would be caught by
the compiler.

>
>> Or are you just engaging
>> in your favourite hobby - taking something that other people see as a
>> convenient way to write clearer code and using it for yet another
>> meaningless rant against C?
>
> No. For me case sensitivity means code that ISN'T clearer because people
> exploit that subtle difference in case between otherwise identical
> names: to use them for different purposes not just within the same
> scope, but across a program, where you have to keep doing a double-take.
>

Ah, it's the old "some people write code I didn't like, therefore the
language is bad" argument. You do like to take your own personal
opinion and think of it as global rules that should apply to everyone.
And you do like to take the worst (in your not so humble opinion)
examples and assume all code is written that way.

Re: Why does C allow structs to have a tag?

<lTnvI.590118$PPIc.288620@fx15.ams4>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16884&group=comp.lang.c#16884

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!2.eu.feeder.erje.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!feeder1.feed.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx15.ams4.POSTED!not-for-mail
Subject: Re: Why does C allow structs to have a tag?
Newsgroups: comp.lang.c
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
<20210606075302.305@kylheku.com> <s9iurd$d7c$1@gioia.aioe.org>
<s9j6mv$v9r$1@dont-email.me> <3R9vI.65671$jM2.54125@fx02.ams4>
<s9kfn9$plt$1@dont-email.me> <ocmvI.707714$7Kb.680010@fx37.ams4>
<s9kvni$ah$1@dont-email.me>
From: bc...@freeuk.com (Bart)
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.0
MIME-Version: 1.0
In-Reply-To: <s9kvni$ah$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 7bit
X-Antivirus: AVG (VPS 210607-0, 07/06/2021), Outbound message
X-Antivirus-Status: Clean
Lines: 35
Message-ID: <lTnvI.590118$PPIc.288620@fx15.ams4>
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Mon, 07 Jun 2021 12:00:17 UTC
Organization: virginmedia.com
Date: Mon, 7 Jun 2021 13:00:15 +0100
X-Received-Bytes: 2642
 by: Bart - Mon, 7 Jun 2021 12:00 UTC

On 07/06/2021 12:25, David Brown wrote:
> On 07/06/2021 12:06, Bart wrote:

>> You mean in the same way that "bart", "Bart" or "BART" all refer to me?
>>
>> Or the fact that if I say them out loud, they all sound identical too?
>
> So you are happy with multiple ways of writing "bart" or "BART" that
> look very different, and would immediately be viewed as different
> identifiers and therefore different meanings to people familiar with
> case-sensitive programming languages. Yet you would be upset with two
> versions of writing the same type in C that are really quite obvious to
> C programmers - and where any mistakes (in real code) would be caught by
> the compiler.

The complaint is really about case-sensitivity in general, across
languages, file systems, OS command lines and, worst because YOU CAN'T
SEE WHAT YOU'RE TYPING, in passwords.

It is just an almighty pain. Fortunately for the most important
situations, common sense prevails and case-insensitivity is used.
(User-names, the first parts of web-addresses, emails and so on. Google
searches too!)

> Ah, it's the old "some people write code I didn't like, therefore the
> language is bad" argument. You do like to take your own personal
> opinion and think of it as global rules that should apply to everyone.
> And you do like to take the worst (in your not so humble opinion)
> examples and assume all code is written that way.

So, you don't take the same advantage of being able to use Foo and foo?

If that case, why do you need a case-sensitive language?

Re: Why does C allow structs to have a tag?

<e7947941-adc7-4219-b8b6-8e6866e7022bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16886&group=comp.lang.c#16886

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:734f:: with SMTP id q15mr7527289qtp.146.1623070852125;
Mon, 07 Jun 2021 06:00:52 -0700 (PDT)
X-Received: by 2002:ac8:7609:: with SMTP id t9mr14112057qtq.381.1623070850301;
Mon, 07 Jun 2021 06:00:50 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 7 Jun 2021 06:00:50 -0700 (PDT)
In-Reply-To: <s9iih0$iu7$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=189.6.254.153; posting-account=xFcAQAoAAAAoWlfpQ6Hz2n-MU9fthxbY
NNTP-Posting-Host: 189.6.254.153
References: <s9iea5$n5c$1@dont-email.me> <s9iih0$iu7$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e7947941-adc7-4219-b8b6-8e6866e7022bn@googlegroups.com>
Subject: Re: Why does C allow structs to have a tag?
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Mon, 07 Jun 2021 13:00:52 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Thiago Adams - Mon, 7 Jun 2021 13:00 UTC

On Sunday, June 6, 2021 at 10:28:10 AM UTC-3, David Brown wrote:
[...]
> But in general if you have two "struct" declarations, these define
> different types - even if they contain the same members. So if you want
> to use the type more than once, you need to give it a name - either
> using a tag or by making it part of a typedef.

In some cases creating a name just make the code more complex.

I wish I could create template structs using macros.

#define vector(T) { T * data; int size, capacity; }

void F(struct vector(Card) * v);

this convention has more information associated than a typedef using
plural name for instance.

void F(struct Cards * v);

Similar of "struct Card cards[] " it brings the information about
the characteristics of the type.

Imagine in C if each time we need array of something
we have to assign a name to it.

int a[10]; //error you need to create a name for it first.

or each compound literal had to have a name...

C also doesn't have unnamed functions (like C++ lambdas) and
sometimes the name is artificially created and used in just one place like
callbacks.

Re: Why does C allow structs to have a tag?

<7b0c20d8-6bd1-4ce1-9006-452d8c52be9bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16887&group=comp.lang.c#16887

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ae9:e84f:: with SMTP id a76mr8153408qkg.366.1623075934879;
Mon, 07 Jun 2021 07:25:34 -0700 (PDT)
X-Received: by 2002:a37:a405:: with SMTP id n5mr4421223qke.186.1623075934685;
Mon, 07 Jun 2021 07:25:34 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 7 Jun 2021 07:25:34 -0700 (PDT)
In-Reply-To: <lTnvI.590118$PPIc.288620@fx15.ams4>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:3cb9:bcbb:8aa0:ce74;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:3cb9:bcbb:8aa0:ce74
References: <s9iea5$n5c$1@dont-email.me> <0x4vI.109969$Ye1.83143@fx01.ams4>
<20210606075302.305@kylheku.com> <s9iurd$d7c$1@gioia.aioe.org>
<s9j6mv$v9r$1@dont-email.me> <3R9vI.65671$jM2.54125@fx02.ams4>
<s9kfn9$plt$1@dont-email.me> <ocmvI.707714$7Kb.680010@fx37.ams4>
<s9kvni$ah$1@dont-email.me> <lTnvI.590118$PPIc.288620@fx15.ams4>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7b0c20d8-6bd1-4ce1-9006-452d8c52be9bn@googlegroups.com>
Subject: Re: Why does C allow structs to have a tag?
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Mon, 07 Jun 2021 14:25:34 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Malcolm McLean - Mon, 7 Jun 2021 14:25 UTC

On Monday, 7 June 2021 at 13:00:30 UTC+1, Bart wrote:
>
> So, you don't take the same advantage of being able to use Foo and foo?
>
> If that case, why do you need a case-sensitive language?
>
If the language is case-insensitive, you don't want the same identifier to
appear in the source in different cases. That confuses anyone who doesn't
know that the language is case insensitive, or who doesn't know that the
programmer who wrote the code knows that the language is case
insensitive, or who hasn't been told why such an odd practice is followed
(there might be reasons, such as attaching metadata to an identifier).

So in fact what you want is not a case insensitive language, but a language
which disallows identifiers which are identical except in case. Alternatively
a language which enforces rules such as "local variables must be lower case,
functions must start with an uppercase letter".

There are good arguments against allowing C's free for all. Virtually every coding
standard is more restrictive than C in the identifiers that it allows. However
backwards compatibility is all.

Pages:12345678910111213141516
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor