Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #153651
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: typedef ... refactored |
| Date | 2020-08-14 12:32 -0700 |
| Organization | None to speak of |
| Message-ID | <87o8ndxbts.fsf@nosuchdomain.example.com> (permalink) |
| References | (6 earlier) <SAvZG.2442895$fgO.1865466@fx12.am4> <rh61ij$h7d$1@dont-email.me> <rh683a$oi0$1@dont-email.me> <87wo21xhjx.fsf@nosuchdomain.example.com> <rh6nj6$q5t$1@dont-email.me> |
David Brown <david.brown@hesbynett.no> writes:
> On 14/08/2020 19:29, Keith Thompson wrote:
>> David Brown <david.brown@hesbynett.no> writes:
>> [...]
>>> The distinction between "struct X" and "typedef X" namespaces is
>>> unavoidable in C, and useful as it lets you use the same name for a
>>> struct and its typedef. (The alternative is to do as C++ did - make "X"
>>> automatically a typedef for "struct X". That is, IMHO, better - but it
>>> was a change that could be made for C++ when C++ was new, not for C when
>>> C was already old.)
>>
>> Strictly speaking, C++ doesn't make automatically create typedefs. It
>> has the same typedef feature that C has, and it's used only when you use
>> the "typedef" keyword. The difference is that struct tags (also enum,
>> union, and class tags) are directly visible.
>>
>> You could achieve (mostly?) the same effect by using automatically
>> created typedefs, but that's not what C++ does.
>
> Yes - calling it "automatic typedefs" is merely a convenience to refer
> to the effect, rather than being technically accurate.
And I think that just saying that the name is directly visible is both
technically accurate and even more convenient.
> (Can you think of any way in which there would be a difference in C++ if
> it did do "automatic typedefs" here? I know it's OT, but I'd be curious
> if you can think of any cases.)
I can't think of any such cases (which doesn't mean there aren't any).
In C it's legal to define struct foo and enum foo in the same scope; in
C++ it's illegal. But if C++ actually did "automatic typedefs", the
effect would be the same.
The implicit typedef would have to be created when the tag name first
appears, because you can refer to "struct foo" as "foo" even inside the
definition.
struct foo {
foo *next; // legal in C++, illegal in C
};
typedef struct bar {
bar *next; // Still illegal in C
} bar;
Apparently this is illegal in C++:
typedef struct foo {
int n;
} foo;
struct foo obj;
because the name "foo" hides the struct tag even when it appears after
the "struct" keyword, but that's not an example of what you're asking
about.
--
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 */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
typedef ... refactored G G <gdotone@gmail.com> - 2020-08-09 01:07 -0700
Re: typedef ... refactored G G <gdotone@gmail.com> - 2020-08-09 01:46 -0700
Re: typedef ... refactored Richard Damon <Richard@Damon-Family.org> - 2020-08-09 08:09 -0400
Re: typedef ... refactored Manfred <noname@add.invalid> - 2020-08-09 18:08 +0200
Re: typedef ... refactored Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-08-09 09:29 +0000
Re: typedef ... refactored Johann Klammer <klammerj@NOSPAM.a1.net> - 2020-08-09 13:29 +0200
Re: typedef ... refactored Bonita Montero <Bonita.Montero@gmail.com> - 2020-08-09 13:53 +0200
Re: typedef ... refactored Poprocks <please@replytogroup.com> - 2020-08-10 20:37 +0000
Re: typedef ... refactored Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-08-10 13:49 -0700
Re: typedef ... refactored Poprocks <please@replytogroup.com> - 2020-08-10 23:09 +0000
Re: typedef ... refactored Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-08-11 07:14 +0000
Why not indeed??? (Was: typedef ... refactored) gazelle@shell.xmission.com (Kenny McCormack) - 2020-08-11 07:48 +0000
Re: typedef ... refactored Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-08-11 10:56 +0100
Re: typedef ... refactored Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-08-28 04:08 -0700
Re: typedef ... refactored Bonita Montero <Bonita.Montero@gmail.com> - 2020-08-11 08:10 +0200
Re: typedef ... refactored Anton Shepelev <anton.txt@gmail.com> - 2020-08-13 00:52 +0300
Re: typedef ... refactored Bonita Montero <Bonita.Montero@gmail.com> - 2020-08-14 14:13 +0200
Re: typedef ... refactored Bart <bc@freeuk.com> - 2020-08-14 13:37 +0100
Re: typedef ... refactored Bonita Montero <Bonita.Montero@gmail.com> - 2020-08-14 14:54 +0200
Re: typedef ... refactored David Brown <david.brown@hesbynett.no> - 2020-08-14 16:46 +0200
Re: typedef ... refactored Bart <bc@freeuk.com> - 2020-08-14 16:59 +0100
Re: typedef ... refactored David Brown <david.brown@hesbynett.no> - 2020-08-14 21:05 +0200
Re: typedef ... refactored Bart <bc@freeuk.com> - 2020-08-14 20:51 +0100
Re: typedef ... refactored antispam@math.uni.wroc.pl - 2020-08-16 13:36 +0000
Re: typedef ... refactored Bart <bc@freeuk.com> - 2020-08-16 15:58 +0100
Re: typedef ... refactored antispam@math.uni.wroc.pl - 2020-08-16 18:10 +0000
Re: typedef ... refactored Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-08-14 13:23 -0700
Re: typedef ... refactored David Brown <david.brown@hesbynett.no> - 2020-08-16 19:48 +0200
[OT] words. Was: typedef ... refactored Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-08-16 20:08 +0100
Re: [OT] words. Was: typedef ... refactored David Brown <david.brown@hesbynett.no> - 2020-08-17 10:50 +0200
Re: [OT] words. Was: typedef ... refactored Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-08-17 12:00 +0100
Re: typedef ... refactored Anton Shepelev <anton.txt@g{oogle}mail.com> - 2020-08-17 17:51 +0300
Re: typedef ... refactored Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-08-17 16:06 +0100
Re: typedef ... refactored Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-08-17 10:48 -0700
Re: typedef ... refactored scott@slp53.sl.home (Scott Lurndal) - 2020-08-17 19:36 +0000
Re: typedef ... refactored Siri Cruise <chine.bleu@yahoo.com> - 2020-08-17 14:06 -0700
Re: typedef ... refactored Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-08-28 03:53 -0700
Re: typedef ... refactored Kaz Kylheku <793-849-0957@kylheku.com> - 2020-08-28 15:30 +0000
Re: typedef ... refactored Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-08-29 02:24 +0100
Re: typedef ... refactored Bonita Montero <Bonita.Montero@gmail.com> - 2020-08-14 18:37 +0200
Re: typedef ... refactored Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-08-14 10:29 -0700
Re: typedef ... refactored David Brown <david.brown@hesbynett.no> - 2020-08-14 21:10 +0200
Re: typedef ... refactored Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-08-14 12:32 -0700
Re: typedef ... refactored G G <gdotone@gmail.com> - 2020-08-09 05:44 -0700
Re: typedef ... refactored Barry Schwarz <schwarzb@delq.com> - 2020-08-09 08:12 -0700
Re: typedef ... refactored G G <gdotone@gmail.com> - 2020-08-09 08:32 -0700
Re: typedef ... refactored John Bode <jfbode1029@gmail.com> - 2020-08-12 11:45 -0700
Re: typedef ... refactored Bart <bc@freeuk.com> - 2020-08-12 19:59 +0100
Re: typedef ... refactored Siri Cruise <chine.bleu@yahoo.com> - 2020-08-12 14:16 -0700
Re: typedef ... refactored Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-08-28 05:05 -0700
Re: typedef ... refactored Anton Shepelev <anton.txt@gmail.com> - 2020-08-13 00:41 +0300
csiph-web