strange difference between gcc versions

C

Christof Warlich

Hi,

the following compiles with gcc 2.95.3 but gives this error
with gcc 3.4.4:

~/tmp> gcc tst.cc
tst.c: In function `int main()':
tst.c:4: error: data member may not have variably modified type
`int[((unsignedint)((int)i))]'

int main(void) {
int i = 2;
struct X {
int a;
} x;
return 0;
}

while

int main(void) {
int i = 2;
int a;
return 0;
}

comiles with both gcc versions.

Any ideas why the newer gcc version only allows to create a dynamic
array, but not a dynamic type on the stack? Even more confusing,
both examples compile fine even with gcc 3.4.4 as C-module, i.e.

gcc tst.c

Christof
 
P

Phlip

Christof said:
int main(void) {
int i = 2;
struct X {
int a;


Both nested types accessing automatic (local) variables, and arrays
dimensioned via integers that are not compile time constants, are on-topic
on a newsgroup or mailing list discussing gcc.

This newsgroup is only qualified to discuss Stardard C++, which decrees that
all arrays, without 'new', must size via compile-time constants, and that
nested classes can only access static things in the nesting class or
function.

Your trouble with g++ might be due to compiler specific extensions which ran
into the technical reasons for these restrictions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top