Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #153642
| Subject | Re: typedef ... refactored |
|---|---|
| Newsgroups | comp.lang.c |
| References | (4 earlier) <20200813005227.b02c40b51ddf5ad71c7ca82b@gmail.com> <rh5v58$349$1@dont-email.me> <SAvZG.2442895$fgO.1865466@fx12.am4> <rh61ij$h7d$1@dont-email.me> <rh683a$oi0$1@dont-email.me> |
| From | Bart <bc@freeuk.com> |
| Message-ID | <4yyZG.1646292$6_j.1423379@fx37.ams4> (permalink) |
| Organization | virginmedia.com |
| Date | 2020-08-14 16:59 +0100 |
On 14/08/2020 15:46, David Brown wrote:
> On 14/08/2020 14:54, Bonita Montero wrote:
>>> There is also having distinct namespaces which is nonsense:
>>> typedef struct X {int a;} X;
>>> X:;
>>> There are 3 X's within the same scope: a struct tag X, a typedef X and
>>> a label X.
>>
>> That's just good for confusion and nothing more.
>>
>
> Labels are almost unused in most C programming (other than for switch
> statements).
That begs the question of why they need their own namespace.
And when they are used, it is primarily for error handling
> or exiting nested loops - anyone who uses a label with a name that
> conflicts with type identifiers (or any other identifier) deserves any
> problems they get.
>
> 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.)
>
> It would be daft for a program to use "struct X" and a "typedef ... X"
> for different types. But all programming languages allow daft and
> confusing names - at some point, the programmer needs to take
> responsibility for writing code that is not confusing. (I'm sure even
> your language lets you use OOO0OOOOO and OOOO0OOOO as two different
> identifiers.)
>
But those are poorly chosen identifiers. Take a better one such as
"target", used as a variable name inside a C function.
Can you re-use that name for other things even within the same scope?
The answer is yes:
Variable name: target (this is the start point)
Struct/enum tag: target
Label: target
Any more? Well we can mix up the letter case, so have Target, TARGET,
TarGet and so on. That gives 64 combinations for each of those 3
namespaces, total 192 names that, when spoken or written in normal
English, are still all "target".
Any more? Yes; 128 of those can reused in any separate block scope
within a function (label scopes are function-wide). And there can be any
number of blocks. So there are can be /unlimited/ numbers of the same
"target" identifier within any function. Good luck trying to pinpoint a
particular one during a conversation.
(In my language, there can be at most ONE "target" identifier in scope
in any function, no matter what mix of case it might use.
For both languages I'm excluding qualified versions of "target" that
might follow a "." name resolution operator, eg. member names.)
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