Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #153576
| From | Anton Shepelev <anton.txt@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: typedef ... refactored |
| Date | 2020-08-13 00:41 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <20200813004147.9548ed1e52f166ef19375d8b@gmail.com> (permalink) |
| References | <7a5f16a3-d30d-46ec-9926-b0736428902do@googlegroups.com> |
G G:
> the following comes from "C How to Program"
> by Deitel & Deitel p.501 (refactored somewhat)
>
> struct treeNode
> {
> struct treeNode *leftPtr;
> int data; // node value
> struct treeNode *rightPtr;
>
> }; // end structure treeNode
>
> typedef struct treeNode TreeNode; // synonym for struct treeNode (1)
>
> typedef TreeNode *TreeNodePtr; // synonym for TreeNode* (2)
>
> [...]
> question why did the authors use so many typedef(s)?
They used only two. Perhaps it was due a background of an
academic programming language such as Pascal or Modula,
where the idiom is to declare a record type denoted by a
single identifer (no `struct' prefix) and a type of pointer
to that type, e.g. in Pascal:
type PTreeNode = ^TTreeNode; (* forward pointer declaraion *)
TTreeNode = record
Left : PTreeNode;
Data : integer;
Right: PTreeNode;
end;
This may explain why they did not mix the struct declaration
and type definition, preferring to do one thing at a time:
typedef struct treeNode
{
struct treeNode *leftPtr;
int data; // node value
struct treeNode *rightPtr;
} TreeNode;
I can't blame them for missing the perspicuity of Pascal.
Notice also the graphical-symmetrical layout of the
structure, as if the author(s) had a predominantly visual
thinking. In my opinion, it a sin, and the members should
grouped by the principle of cohesion, accoridng to their
nature.
But why the illiterate title: "C How to Program", I truly
cannot conjecture. Maybe Yoda was chief editor...
--
() ascii ribbon campaign -- against html e-mail
/\ http://preview.tinyurl.com/qcy6mjc [archived]
Back to comp.lang.c | Previous | Next — Previous 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 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