Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #153510

Re: typedef ... refactored

Path csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: typedef ... refactored
Date Mon, 10 Aug 2020 13:49:59 -0700
Organization None to speak of
Lines 38
Message-ID <875z9q445k.fsf@nosuchdomain.example.com> (permalink)
References <7a5f16a3-d30d-46ec-9926-b0736428902do@googlegroups.com> <rgoo37$3ca$1@dont-email.me> <slrnrj3c08.u86.please@logancomp.rathbonelaw.com>
Mime-Version 1.0
Content-Type text/plain
Injection-Info reader02.eternal-september.org; posting-host="9a8e452c1518fb0522423c029e73ba21"; logging-data="31120"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XMVddj2EIaptQFI8XVUR6"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)
Cancel-Lock sha1:T6QLZAR0+oTgxNHCo9ds1vV4hj4= sha1:7FUNFtCa68OeJNuTHQHqgOEeymE=
Xref csiph.com comp.lang.c:153510

Show key headers only | View raw


Poprocks <please@replytogroup.com> writes:
> On 2020-08-09, Bonita Montero wrote:
>>> typedef struct treeNode TreeNode; // synonym for struct treeNode  (1)
>>
>> Why not "typedef struct treeNode treeNode;" ?
>
> Just a matter of practice/personal preference, methinks.
>
> Personally I don't care for having a struct identifier share the same
> name as a typedef.  Sometimes I put an underscore in front of the struct
> identifier to distinguish it in my mind from the typedef I end up
> declaring.

Identifiers starting with underscores are a bad idea.  They're generally
reserved to the implementation.  The rules are a bit more involved than
that, but it's easier just to avoid defining such identifiers
altogether.

The actual rules:

- All identifiers that begin with an underscore and either an uppercase
  letter or another underscore are always reserved for any use.
  
- All identifiers that begin with an underscore are always reserved for
  use as identifiers with file scope in both the ordinary and tag name
  spaces.

Personally I don't bother with typedefs for struct types.  The type
already has a perfectly good name, "struct treeNode".  I see little
advantage in giving it another one.  But if you like having a name
that's a single identifier, you might as well use the same identifier
for the tag and the typedef.  Or if not, use some consistent convention
like appending "_s" to the tag name.

-- 
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 | NextPrevious in thread | Next in thread | Find similar


Thread

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 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 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 Anton Shepelev <anton.txt@gmail.com> - 2020-08-13 00:41 +0300

csiph-web