Reply by Dave Hansen January 26, 20052005-01-26
On Tue, 25 Jan 2005 18:30:34 -0500, Roberto Waltman
<usenet@rwaltman.net> wrote:

>iddw@hotmail.com wrote: >>If you can't, I believe the following is supposed to work as well: >> >> extern const Node_t n1,n2,n3; >> >> static const Node_t n1 = { &n2, &n3, "Node 1" }; >> static const Node_t n2 = { &n3, &n1, "Node 2" }; >> static const Node_t n3 = { &n1, &n2, "Node 3" }; >> >>This is apparently how things were done before the standard, and the >>standard supports the old code. > >gcc accepts that, unless you are using the "-pedantic" switch. Then it >produces warnings, (not errors,) about "static declaration following >non-static".
Actually, I mis-spoke. Change the first line to const Node_t n1,n2,n3; (i.e., remove the "extern" and leave off the "static") and it should be legal.
> >What C is missing is forward declarations, a la Pascal ...
Not C, just the OP's compiler. Regards, -=Dave -- Change is inevitable, progress is not.
Reply by Hans-Bernhard Broeker January 26, 20052005-01-26
Roberto Waltman <usenet@rwaltman.net> wrote:

> What C is missing is forward declarations, a la Pascal ...
C is has all the forward declarations it needs. -- Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.
Reply by CBFalconer January 26, 20052005-01-26
Roberto Waltman wrote:
>
... snip ...
> > What C is missing is forward declarations, a la Pascal ...
It has them, except they are called prototypes. Neither language can forward declare a variable. Both can declare pointers to undefined types. Pascal simply says that all pointers occupy the same storage space. C uses the incomplete type. -- "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson
Reply by Roberto Waltman January 25, 20052005-01-25
iddw@hotmail.com wrote:
>If you can't, I believe the following is supposed to work as well: > > extern const Node_t n1,n2,n3; > > static const Node_t n1 = { &n2, &n3, "Node 1" }; > static const Node_t n2 = { &n3, &n1, "Node 2" }; > static const Node_t n3 = { &n1, &n2, "Node 3" }; > >This is apparently how things were done before the standard, and the >standard supports the old code.
gcc accepts that, unless you are using the "-pedantic" switch. Then it produces warnings, (not errors,) about "static declaration following non-static". What C is missing is forward declarations, a la Pascal ... Roberto Waltman. [ Please reply to the group, return address is invalid ]
Reply by Dave Hansen January 25, 20052005-01-25
On Tue, 25 Jan 2005 16:22:18 GMT, no-one@dont-mail-me.com (Robert
Scott) wrote:

[...]
>If you can afford to let n1, n2, and n3 become global, then try this: > >extern const Node_t n1,n2,n3; > > const Node_t n1 = { &n2, &n3, "Node 1" }; > const Node_t n2 = { &n3, &n1, "Node 2" }; > const Node_t n3 = { &n1, &n2, "Node 3" };
If you can't, I believe the following is supposed to work as well: extern const Node_t n1,n2,n3; static const Node_t n1 = { &n2, &n3, "Node 1" }; static const Node_t n2 = { &n3, &n1, "Node 2" }; static const Node_t n3 = { &n1, &n2, "Node 3" }; This is apparently how things were done before the standard, and the standard supports the old code. Regards, -=Dave -- Change is inevitable, progress is not.
Reply by Robert Scott January 25, 20052005-01-25
On 25 Jan 2005 15:03:53 +0100, Mastupristi <cialdi_NO_SP@AM_gmail.com>
wrote:

>We use IAR 78000 C-Compiler V3.21A/386. >I want to initialize a static const list of structures as follow: > >typedef struct rec >{ > const struct rec *succ; > const struct rec *prec; > char *str; >}Node_t; > >static const Node_t n1; >static const Node_t n2; >static const Node_t n3; > >static const Node_t n1 = { &n2, &n3, "Node 1" }; >static const Node_t n2 = { &n3, &n1, "Node 2" }; >static const Node_t n3 = { &n1, &n2, "Node 3" }; > > >but this doesn't work. I obtain a "redefined" error on the last 3 lines. >How can I initialize this list?
If you can afford to let n1, n2, and n3 become global, then try this: extern const Node_t n1,n2,n3; const Node_t n1 = { &n2, &n3, "Node 1" }; const Node_t n2 = { &n3, &n1, "Node 2" }; const Node_t n3 = { &n1, &n2, "Node 3" }; -Robert Scott Ypsilanti, Michigan (Reply through this forum, not by direct e-mail to me, as automatic reply address is fake.)
Reply by Mastupristi January 25, 20052005-01-25
On 25 Jan 2005 16:00:47 GMT
Richard <RichardRapier@netscape.net> wrote:

> To make it work with your buggy compiler, try removing the tentative > declarations. > > typedef struct rec > > const struct rec *succ; > const struct rec *prec; > char *str; > }Node_t; > > static const Node_t n1 = { &n2, &n3, "Node 1" }; > static const Node_t n2 = { &n3, &n1, "Node 2" }; > static const Node_t n3 = { &n1, &n2, "Node 3" };
this was the first try. It doesn't work. thanks -- Mastupristi?
Reply by Richard January 25, 20052005-01-25
Mastupristi <cialdi_NO_SP@AM_gmail.com> wrote in 
news:20050125150026.00005b95.cialdi_NO_SP@AM_gmail.com:

> We use IAR 78000 C-Compiler V3.21A/386. > I want to initialize a static const list of structures as follow: > > typedef struct rec > { > const struct rec *succ; > const struct rec *prec; > char *str; > }Node_t; > > static const Node_t n1; > static const Node_t n2; > static const Node_t n3; > > static const Node_t n1 = { &n2, &n3, "Node 1" }; > static const Node_t n2 = { &n3, &n1, "Node 2" }; > static const Node_t n3 = { &n1, &n2, "Node 3" }; > > > but this doesn't work. I obtain a "redefined" error on the last 3
lines.
> How can I initialize this list? > It is mandatory that all structures are const, and I prefer if they are > also static. > > thanks >
To make it work with your buggy compiler, try removing the tentative declarations. typedef struct rec { const struct rec *succ; const struct rec *prec; char *str; }Node_t; static const Node_t n1 = { &n2, &n3, "Node 1" }; static const Node_t n2 = { &n3, &n1, "Node 2" }; static const Node_t n3 = { &n1, &n2, "Node 3" }; -- Richard
Reply by Vadim Borshchev January 25, 20052005-01-25
On 25 Jan 2005 15:52:23 +0100, Mastupristi <cialdi_NO_SP@AM_gmail.com> 
wrote:

> As you can see in definition of n1 is used &n2 and &n3, so the > declaration > of n2 and n3 must be placed before this line. If I am wrong tell me.
You are right, and I was wrong.
> note that I tried the same code with gcc and it works fine.
It works in armcc and clarm as well. Your compiler seems to have a bug. Vadim
Reply by Mastupristi January 25, 20052005-01-25
On Tue, 25 Jan 2005 14:23:01 -0000
Vadim Borshchev <vadim.borshchev@127.0.0.1> wrote:

> > static const Node_t n1; > > static const Node_t n2; > > static const Node_t n3; > > > static const Node_t n1 = { &n2, &n3, "Node 1" }; > > static const Node_t n2 = { &n3, &n1, "Node 2" }; > > static const Node_t n3 = { &n1, &n2, "Node 3" }; > > Hint: any good book on C language describes the difference between > declaration and definition.
thanks professor, but this hint doesn't help me. I know the difference between declaration and definition. As you can see in definition of n1 is used &n2 and &n3, so the declaration of n2 and n3 must be placed before this line. If I am wrong tell me. But if I place the declaration before, the compiler give the "redeclaration error". note that I tried the same code with gcc and it works fine. Unfortunately gcc cannot compile code for NEC 78F9026A. thanks -- Mastupristi?