Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Kaz Kylheku <kaz@kylheku.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: rms from rosettacode |
| Date | 2011-12-28 19:29 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <20111228111138.529@kylheku.com> (permalink) |
| References | (1 earlier) <20111227115244.994@kylheku.com> <4efa2b39$0$1383$4fafbaef@reader2.news.tin.it> <jddska$550$1@dont-email.me> <jdf43c$aph$1@dont-email.me> <jdf5sd$kd8$1@dont-email.me> |
On 2011-12-28, BartC <bc@freeuk.com> wrote:
> I've been posting here a lot longer, but still have problems with some
> things that should be straightforward to a C programmer.
>
> For example, I had trouble the other night with creating a struct with
> self-referential members. I tried loads of combinations including forward
> declarations and got nowhere. I was about to post here, then came across
> this form in some code that was lying around:
>
> typedef struct snode{
> int value;
> int opcode;
> struct snode *aref,*bref;
> } node;
There is no need for the tag and typedef name to be different. They
are in a different namespace disambiguated by the "struct" keyword:
typedef struct node {
int value;
int opcode;
struct node *aref, *bref;
} node;
Maybe the use of two symbols snode and node adds to your perception
that it is untidy. I mean, if you have N structures, you use 2*N
identifiers in their naming.
> That worked, but how can I turn the 'struct snode*' into a much tidier 'node
> *'? This doesn't work:
This brings to mind an earlier Eric Sosman posting, where he recounted
an analogy from a friend: maybe you're trying to clean the beach of bottle caps
and cigarette butts so that the areas around the rotting whale carcasses are
nice and clean.
How tidy will the overall program be when it grows large and complex?
Big C programs are very hard to keep tidy. Even if the program is developed by
a single developer in his spare time, who is single-mindedly dedicated to
tidiness, tidiness will eventually give way here and there to functionality.
> typedef struct {
> int value;
> int opcode;
> node *aref,*bref;
> } node;
Perfectly valid C++, hint hint:
struct node {
node *aref;
};
In C there is no way around the keyword struct occuring twice, e.g:
/* A */
typedef struct node node;
struct node {
node *aref, *bref;
};
/* B */
struct node {
typedef struct node node;
node *aref, *bref;
};
B loses C++ compatibility though. The typedef name is not scoped to
the struct in C, but in C++ it is in class scope.
Well, there is always preprocessing:
#define node struct node
node { /* oh, boy! */
node *a, *b;
}
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-27 11:25 +0100
Re: rms from rosettacode James Kuyper <jameskuyper@verizon.net> - 2011-12-27 06:48 -0500
Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-27 13:01 +0100
Re: rms from rosettacode James Kuyper <jameskuyper@verizon.net> - 2011-12-27 07:10 -0500
Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-27 13:36 +0100
Re: rms from rosettacode James Kuyper <jameskuyper@verizon.net> - 2011-12-27 10:04 -0500
Re: rms from rosettacode Keith Thompson <kst-u@mib.org> - 2011-12-27 14:42 -0800
Re: rms from rosettacode James Kuyper <jameskuyper@verizon.net> - 2011-12-27 18:46 -0500
Re: rms from rosettacode 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-27 09:49 -0800
Re: rms from rosettacode "BartC" <bc@freeuk.com> - 2011-12-27 18:14 +0000
Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-27 19:33 +0100
Re: rms from rosettacode jt@toerring.de (Jens Thoms Toerring) - 2011-12-27 19:04 +0000
Re: rms from rosettacode Keith Thompson <kst-u@mib.org> - 2011-12-27 14:45 -0800
Re: rms from rosettacode blp@cs.stanford.edu (Ben Pfaff) - 2011-12-27 14:57 -0800
Re: rms from rosettacode "BartC" <bc@freeuk.com> - 2011-12-27 19:06 +0000
Re: rms from rosettacode Bull in a China Blue Shop <chine.bleu@yahoo.com> - 2011-12-27 16:16 -0800
Re: rms from rosettacode James Kuyper <jameskuyper@verizon.net> - 2011-12-27 14:11 -0500
Re: rms from rosettacode Seebs <usenet-nospam@seebs.net> - 2011-12-27 20:13 +0000
Re: rms from rosettacode Johann Klammer <klammerr@NOSPAM.aon.at> - 2011-12-28 00:23 +0100
Re: rms from rosettacode 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-27 15:54 -0800
Re: rms from rosettacode Keith Thompson <kst-u@mib.org> - 2011-12-27 22:53 -0800
Re: rms from rosettacode Seebs <usenet-nospam@seebs.net> - 2011-12-28 06:29 +0000
Re: rms from rosettacode 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-28 02:45 -0800
Re: rms from rosettacode Kaz Kylheku <kaz@kylheku.com> - 2011-12-27 19:53 +0000
Re: rms from rosettacode Seebs <usenet-nospam@seebs.net> - 2011-12-27 20:13 +0000
Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-27 21:31 +0100
Re: rms from rosettacode Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-12-27 20:49 -0500
Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-28 11:42 +0100
Re: rms from rosettacode Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-29 08:18 -0800
Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-28 11:54 +0100
Re: rms from rosettacode Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-12-29 04:12 +0200
Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-29 14:38 +0100
Re: rms from rosettacode Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-28 02:26 -0800
Re: rms from rosettacode Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-12-28 21:35 -0500
Re: rms from rosettacode superpollo <superpollo@tznvy.pbz> - 2011-12-29 14:10 +0100
Re: rms from rosettacode James Kuyper <jameskuyper@verizon.net> - 2011-12-28 08:03 -0500
Re: rms from rosettacode "BartC" <bc@freeuk.com> - 2011-12-28 13:32 +0000
Re: rms from rosettacode Dr Nick <3-nospam@temporary-address.org.uk> - 2011-12-28 13:41 +0000
Re: rms from rosettacode Kaz Kylheku <kaz@kylheku.com> - 2011-12-28 19:29 +0000
Re: rms from rosettacode Keith Thompson <kst-u@mib.org> - 2011-12-28 13:47 -0800
Re: rms from rosettacode Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-12-29 04:19 +0200
Re: rms from rosettacode Kaz Kylheku <kaz@kylheku.com> - 2011-12-28 19:11 +0000
csiph-web