This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Member initialization of arrays of constants
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Member initialization of arrays of constants
- From: Michael Schwendt <mschwendt at web dot de>
- Date: Sun, 23 Jul 2000 12:10:48 +0200 (CEST)
- Organization: Private Linux Intranet
Red Hat Linux release 6.2 (Zoot) i386
on i586 CPU with 64 MB RAM
egcs 1.1.2
(glibc 2.1.3, libstdc++.so.2.8.0 and 2.9, libg++.so.2.7.2.8)
Options used: g++ s.cpp -c
If I'm informed correctly, initialization of member constants
can only be performed via a ctor's initializer-list. Member arrays
of constants cannot be initialized like aggregates and cannot be
initialized via a ctor's initializer-list either.
Egcs, however, compiles the following code examples fine by
mistake:
Example 1: // ----------------------------------------------------
struct A
{
const char a[4];
int i;
};
void f()
{
A a = { {'T','E','S','T'}, 1 }; // not allowed, but compiles
// This would be okay, if it were an array of non-constants
// in the struct.
}
Example 2: // ----------------------------------------------------
struct A
{
const char a[4];
int i;
};
class C
{
static const A a;
};
const A C::a = { 'T','E','S','T', 2 }; // not allowed, but compiles
Regards,
Mike