public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* const static initializers versionitis
@ 2000-08-18  8:43 Gianni Mariani
  2000-08-22  8:12 ` Gianni Mariani
  0 siblings, 1 reply; 10+ messages in thread
From: Gianni Mariani @ 2000-08-18  8:43 UTC (permalink / raw)
  To: gcc

The code below compiles fine with egcs-2.91.66 but fails with 2.95.2 and

2.95.3 .   Am I missing somthing ?  Any way of getting the egcs-2.91.66
behaviour in 2.95.3 ?

g++2.95.2 -c yy.cpp
yy.cpp:7: uninitialized const `bar'
yy.cpp:9: uninitialized const `tar'
--------- yy.cpp -----------
struct foo {
        const struct foo * y;
        char    who[ 10 ];
};

const static struct foo bar[];

const static struct foo tar[];

const static struct foo bar[] = {
        tar, "bar"
};

const static struct foo tar[] = {
        bar, "tar"
};

const char * zefuc()
{
        return tar->y->who;
}



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: const static initializers versionitis
  2000-08-18  8:43 const static initializers versionitis Gianni Mariani
@ 2000-08-22  8:12 ` Gianni Mariani
  2000-08-22  8:29   ` Alexandre Oliva
  0 siblings, 1 reply; 10+ messages in thread
From: Gianni Mariani @ 2000-08-22  8:12 UTC (permalink / raw)
  To: Gianni Mariani; +Cc: gcc

help - please ...

Why were forward declarations of const arrays removed from g++
since 2.95.2 ?

Isn't this a gcc bug ? i.e. not being able to forward declare an
array instance ?

The code still compiles fine in gcc so I would have some level
of expectation that "const"ness should not change the behaviour
of the compiler.

Is there a compiler switch that reinstates the desired behaviour ?

> 
> 
> The code below compiles fine with egcs-2.91.66 but fails with 2.95.2 and
> 
> 2.95.3 .   Am I missing somthing ?  Any way of getting the egcs-2.91.66
> behaviour in 2.95.3 ?
> 
> g++2.95.2 -c yy.cpp
> yy.cpp:7: uninitialized const `bar'
> yy.cpp:9: uninitialized const `tar'
> --------- yy.cpp -----------
struct foo {
        const struct foo * y;
        char    who[ 10 ];
};

const static struct foo bar[];

const static struct foo tar[];

const static struct foo bar[] = {
        tar, "bar"
};

const static struct foo tar[] = {
        bar, "tar"
};

const char * zefuc()
{
        return tar->y->who;
}




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: const static initializers versionitis
  2000-08-22  8:12 ` Gianni Mariani
@ 2000-08-22  8:29   ` Alexandre Oliva
  2000-08-22  9:04     ` Gianni Mariani
  0 siblings, 1 reply; 10+ messages in thread
From: Alexandre Oliva @ 2000-08-22  8:29 UTC (permalink / raw)
  To: Gianni Mariani; +Cc: Gianni Mariani, gcc

On Aug 22, 2000, Gianni Mariani <gianni_@uluru.mariani.ws> wrote:

> Why were forward declarations of const arrays removed from g++
> since 2.95.2 ?

`extern' is the keyword to forward-declare data in namespace scope.

> Isn't this a gcc bug?

Nope.

> The code still compiles fine in gcc so I would have some level
> of expectation that "const"ness should not change the behaviour
> of the compiler.

const POD must be initialized.

> Is there a compiler switch that reinstates the desired behaviour ?

-fpermissive, maybe?

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: const static initializers versionitis
  2000-08-22  8:29   ` Alexandre Oliva
@ 2000-08-22  9:04     ` Gianni Mariani
  2000-08-22  9:27       ` Alexandre Oliva
  0 siblings, 1 reply; 10+ messages in thread
From: Gianni Mariani @ 2000-08-22  9:04 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc

Thx Alexandre

-fpermissive seems not to be the solution ...
$ g++ -fpermissive -c yy.cpp
yy.cpp:7: uninitialized const `bar'
yy.cpp:9: uninitialized const `tar'

> const POD must be initialized.  ....

So how does one forward declare a const POD ?  As you can see in the
code the arrays point to each other !

I have 2 applications I want to move to the later C++ compiler and both
applications generate code with statically initialized arrays of various
kinds of objects which should be declared const.

So it seems as though the rule "const POD must be initialized" would
preclude initializing these kind of data structures - kind of weak
wouldn't
you say ?

So the alternative would be to not make them const and not make them
static and then we pollute the name space - which is also bad - .

Do you know what the motivation is behind this rule ?  Is it just silly
or
is there a reason for the madness ?

G


Alexandre Oliva wrote:

> On Aug 22, 2000, Gianni Mariani <gianni_@uluru.mariani.ws> wrote:
>
> > Why were forward declarations of const arrays removed from g++
> > since 2.95.2 ?
>
> `extern' is the keyword to forward-declare data in namespace scope.
>
> > Isn't this a gcc bug?
>
> Nope.
>
> > The code still compiles fine in gcc so I would have some level
> > of expectation that "const"ness should not change the behaviour
> > of the compiler.
>
> const POD must be initialized.
>
> > Is there a compiler switch that reinstates the desired behaviour ?
>
> -fpermissive, maybe?
>
> --
> Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
> Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
> CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
> Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: const static initializers versionitis
  2000-08-22  9:04     ` Gianni Mariani
@ 2000-08-22  9:27       ` Alexandre Oliva
  2000-08-22 10:59         ` Gianni Mariani
  0 siblings, 1 reply; 10+ messages in thread
From: Alexandre Oliva @ 2000-08-22  9:27 UTC (permalink / raw)
  To: Gianni Mariani; +Cc: gcc

On Aug 22, 2000, Gianni Mariani <gianni@mariani.ws> wrote:

> So how does one forward declare a const POD?

> Alexandre Oliva wrote:

>> `extern' is the keyword to forward-declare data in namespace scope.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: const static initializers versionitis
  2000-08-22  9:27       ` Alexandre Oliva
@ 2000-08-22 10:59         ` Gianni Mariani
  2000-08-23  2:59           ` Alexandre Oliva
  0 siblings, 1 reply; 10+ messages in thread
From: Gianni Mariani @ 2000-08-22 10:59 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc

Forgot to mention - tried that !

I want a "static" - so declaring it extern is specifically not
what I (ideally) would want. i.e. can't have an "extern static"
declaration.

$ g++ -c yy.cpp
yy.cpp:7: multiple storage classes in declaration of `bar'
yy.cpp:9: multiple storage classes in declaration of `tar'

------------ new yy.cpp ---------------
struct foo {
 const struct foo * y;
 char who[ 10 ];
};

extern const static struct foo bar[];

extern const static struct foo tar[];

const static struct foo bar[] = {
 tar, "bar"
};

const static struct foo tar[] = {
 bar, "tar"
};


const char * zefuc()
{
 return tar->y->who;
}


>
> On Aug 22, 2000, Gianni Mariani <gianni@mariani.ws> wrote:
>
> > So how does one forward declare a const POD?
>
> > Alexandre Oliva wrote:
>
> >> `extern' is the keyword to forward-declare data in namespace scope.
>
> --
> Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
> Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
> CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
> Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: const static initializers versionitis
  2000-08-22 10:59         ` Gianni Mariani
@ 2000-08-23  2:59           ` Alexandre Oliva
  2000-08-23  8:33             ` Gianni Mariani
  0 siblings, 1 reply; 10+ messages in thread
From: Alexandre Oliva @ 2000-08-23  2:59 UTC (permalink / raw)
  To: Gianni Mariani; +Cc: gcc

On Aug 22, 2000, Gianni Mariani <gianni@mariani.ws> wrote:

> I want a "static" - so declaring it extern is specifically not
> what I (ideally) would want. i.e. can't have an "extern static"
> declaration.

I see.  You'll hopefully have better luck with anonymous namespaces.
AFAICT, there's no way to forward-declare static data items in C++.

namespace {
  extern const struct foo bar[];
  extern const struct foo tar[];

  const struct foo bar[] = { ... };
  const struct foo tar[] = { ... };
}

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: const static initializers versionitis
  2000-08-23  2:59           ` Alexandre Oliva
@ 2000-08-23  8:33             ` Gianni Mariani
  2000-08-23  9:39               ` Alexandre Oliva
  0 siblings, 1 reply; 10+ messages in thread
From: Gianni Mariani @ 2000-08-23  8:33 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc

I don't know how to "export" a symbol from an anonymous
namespace.  But somthing like that would make this ANS's
viable.

$ g++ -c yy.cpp
yy.cpp:20: parse error before `('

------------ yy.cpp ------------
namespace {

struct foo {
        const struct foo * y;
        char    who[ 10 ];
};

extern const struct foo bar[];

extern const struct foo tar[];

const struct foo bar[] = {
        tar, "bar"
};

const struct foo tar[] = {
        bar, "tar"
};

const char * ::zefuc()
{
        return tar->y->who;
}

};

Alexandre Oliva wrote:

> On Aug 22, 2000, Gianni Mariani <gianni@mariani.ws> wrote:
>
> > I want a "static" - so declaring it extern is specifically not
> > what I (ideally) would want. i.e. can't have an "extern static"
> > declaration.
>
> I see.  You'll hopefully have better luck with anonymous namespaces.
> AFAICT, there's no way to forward-declare static data items in C++.
>
> namespace {
>   extern const struct foo bar[];
>   extern const struct foo tar[];
>
>   const struct foo bar[] = { ... };
>   const struct foo tar[] = { ... };
> }
>
> --
> Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
> Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
> CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
> Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: const static initializers versionitis
  2000-08-23  8:33             ` Gianni Mariani
@ 2000-08-23  9:39               ` Alexandre Oliva
  2000-08-23 10:12                 ` Gianni Mariani
  0 siblings, 1 reply; 10+ messages in thread
From: Alexandre Oliva @ 2000-08-23  9:39 UTC (permalink / raw)
  To: Gianni Mariani; +Cc: gcc

On Aug 23, 2000, Gianni Mariani <gianni@mariani.ws> wrote:

> I don't know how to "export" a symbol from an anonymous
> namespace.

An anonymous namespace is implicitly `using'ed :-P by the enclosing
namespace.

> $ g++ -c yy.cpp
> yy.cpp:20: parse error before `('

Move the function definition out of the namespace.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: const static initializers versionitis
  2000-08-23  9:39               ` Alexandre Oliva
@ 2000-08-23 10:12                 ` Gianni Mariani
  0 siblings, 0 replies; 10+ messages in thread
From: Gianni Mariani @ 2000-08-23 10:12 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc

OK - that works. Thanks.

Alexandre Oliva wrote:

> On Aug 23, 2000, Gianni Mariani <gianni@mariani.ws> wrote:
>
> > I don't know how to "export" a symbol from an anonymous
> > namespace.
>
> An anonymous namespace is implicitly `using'ed :-P by the enclosing
> namespace.
>
> > $ g++ -c yy.cpp
> > yy.cpp:20: parse error before `('
>
> Move the function definition out of the namespace.
>
> --
> Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
> Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
> CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
> Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2000-08-23 10:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-18  8:43 const static initializers versionitis Gianni Mariani
2000-08-22  8:12 ` Gianni Mariani
2000-08-22  8:29   ` Alexandre Oliva
2000-08-22  9:04     ` Gianni Mariani
2000-08-22  9:27       ` Alexandre Oliva
2000-08-22 10:59         ` Gianni Mariani
2000-08-23  2:59           ` Alexandre Oliva
2000-08-23  8:33             ` Gianni Mariani
2000-08-23  9:39               ` Alexandre Oliva
2000-08-23 10:12                 ` Gianni Mariani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).