array initializers

R

RezaRob

[ Sorry for double posting to c++.moderated; I made a mistake. ]

I don't know if this is ANSI-C, but in gcc it works perfectly well:

static const char *opcodes[] = {
[3] = "bad_op"
};

However, in c++ it fails! What's the deal?

Thanks.

Reza.
 
I

Ian Collins

RezaRob said:
[ Sorry for double posting to c++.moderated; I made a mistake. ]

I don't know if this is ANSI-C, but in gcc it works perfectly well:
Not in conforming mode.
static const char *opcodes[] = {
[3] = "bad_op"
};

However, in c++ it fails! What's the deal?
It's a C99 extension that isn't part of the current C++ standard, which
predates C99.
 
J

James Kanze

I don't know if this is ANSI-C, but in gcc it works perfectly well:
static const char *opcodes[] = {
[3] = "bad_op"
};
However, in c++ it fails! What's the deal?

It's legal ISO C (according to ISO/IEC 9899::1999), but not
legal ISO C++ (according to ISO/IEC 14882:2003).

As far as I know, this part of C99 will not be adopted into the
next version of C++. (I don't know why. In the case of
structures, it's particularly useful, and generally speaking,
aggregate initialization in C++ is very strongly based on C.)
 

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

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,517
Latest member
Andres38A1

Latest Threads

Top