473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

array initializers

[ 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.
Jan 29 '08 #1
2 1383
RezaRob wrote:
[ 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.

--
Ian Collins.
Jan 29 '08 #2
On Jan 29, 7:01 am, RezaRob <Reza...@gmail.comwrote:
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.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jan 29 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: herbertF | last post by:
Hi guys, In a program (not my own) I encountered the declaration of a constant pointer to an array consisting of two other const pointers to arrays. Not quite sure why they do it so complicated,...
20
by: K.M. Jr. | last post by:
Hi all, Consider this line - char s = "\0"; Does this initialize all array elements to zero ? Thanks.
20
by: Petter Reinholdtsen | last post by:
Is the code fragment 'char a = ("a");' valid ANSI C? The problematic part is '("a")'. I am sure 'char a = "a";' is valid ANSI C, but I am more unsure if it is allowed to place () around the...
3
by: masood.iqbal | last post by:
Hi, I have seen at least two ways to initialize multi-dimensional arrays in C. One of the ways is shown in a sample code snippet below. The other way does not make use of any intermediate...
3
by: Eric Laberge | last post by:
Aloha! I've been reading the standard (May '05 draft, actually) and stumbled across this: 6.7.1 Initialization §20 "If the aggregate or union contains elements or members that are aggregates...
10
by: Ni | last post by:
I found out smth strange in g++ >= 3.3.5 => I was able to do register char buff;//// where outSTDBuffer is a variable!!!! Is it a bug in gcc or specification of c++ changed?? I've noticed this...
7
by: Russell Hind | last post by:
I want to create an array of key value pairs. This code compiles fine: KeyValuePair<string, object> kvps = { new KeyValuePair<string,object>( "int", 5 ), new KeyValuePair<string,object>(...
9
by: barcaroller | last post by:
Can variables be used for array size in C++? I know that in the past, I could not do the following: foo (int x) { type arr; } I have recently seen code that does exactly that. Is it right?
1
by: r035198x | last post by:
Inspiration Inspired by a post by Jos in the Java forum, I have put together a little article on class initializers. Initializers are indeed underutilized by most Java programmers. Once the Java...
24
by: DomoChan | last post by:
the code below will compile in visual c++ 2003, but im not sure its valid. unsigned char myString = ""; after this line executes, all the bytes within myString are indeed set to '0's' but is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.