473,405 Members | 2,262 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,405 software developers and data experts.

{} initializer as expression

Hi,

I was wondering if this kind of things are valid as for the C++
standard? It is working with g++, but it may be either a bug (?) or an
"extension" ...

#include <iostream>

template <size_t N>
struct idx
{
typedef const size_t id[ N ];
void set( id i )
{
size_t j;
for( j = 0 ; j < N ; ++j )
{
i_[ j ] = i[ j ];
}
}

size_t i_[ N ];
};

int main()
{
typedef idx<4>::id id;
idx<4i;
i.set( (id) {2,3,4,5} ); // Initializer used as expression
return 0;
}

Thanks,

Pierre
Aug 14 '06 #1
2 1342
Pierre Barbier de Reuille wrote:
I was wondering if this kind of things are valid as for the C++
standard? It is working with g++, but it may be either a bug (?) or an
"extension" ...
It's an extension. In the standard C++ there are no "compound literals"
(or whatever you prefer to name those things).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 14 '06 #2
On 2006-08-14 10:15:39 -0400, Pierre Barbier de Reuille
<p.****************@free.frsaid:
Hi,

I was wondering if this kind of things are valid as for the C++
standard? It is working with g++, but it may be either a bug (?) or an
"extension" ...

#include <iostream>

template <size_t N>
struct idx
{
typedef const size_t id[ N ];
void set( id i )
{
size_t j;
for( j = 0 ; j < N ; ++j )
{
i_[ j ] = i[ j ];
}
}

size_t i_[ N ];
};

int main()
{
typedef idx<4>::id id;
idx<4i;
i.set( (id) {2,3,4,5} ); // Initializer used as expression
return 0;
}
It's an extension. GCC allows some C99-isms in C++ code as an extension.
http://gcc.gnu.org/onlinedocs/gcc-3....-Literals.html
--
Clark S. Cox, III
cl*******@gmail.com

Aug 14 '06 #3

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

Similar topics

6
by: Clint Olsen | last post by:
What about the following is not computable? It seems that the size of foo is easily computable: typedef struct { char *name; char *data; } Foo; int main(void) {
2
by: Mantorok Redgormor | last post by:
struct mystruct { int a; int b; }; struct mystruct x = { 10, 10 }, y = x; What section in the standard says that y needs a constant? And why can't it resolve x so that y can have a copy of...
6
by: Marty M | last post by:
The following causes the "invalid initializer" message during gcc compile time... char firstword = word(question,1); the "word" function is... char * word(char *phrase, int what) {...body...
22
by: Vijay | last post by:
With the option strict On set..... Dim fs As FileStream = File.OpenRead(strFile) With fs Dim buffer(fs.Length) As Byte ' <--- Option Strict On disallows implicit conversions from 'Long' to...
3
by: vib | last post by:
Hi there, I wish to get some advice on the problem I face in initializing a table. Here is the code. I've an array of strings, ptrNameString . I want to initialize a table, mySoftKeyTable...
2
by: aarklon | last post by:
Hi all, Recently i was reading a c book which contained a section called C pitfalls. it had a paragraph on the following lines:- ...
12
by: Pawel | last post by:
Hallo group members Could You tell hw to write this code in order not to get warning from subject: #include <iostream> using namespace std; using namespace __gnu_cxx; struct entry {
3
by: Ham Pastrami | last post by:
class Point { public: const int x, y; Point(int x, int y); } Point::Point(int x, int y) : x(x), y(y) { }
10
by: Angel Tsankov | last post by:
Hello! Is the following code illformed or does it yield undefined behaviour: class a {}; class b {
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.