By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

initializer needs constant

P: n/a
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 its values?

--
nethlek
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ne*****@tokyo.com (Mantorok Redgormor) wrote in
news:41*************************@posting.google.co m:
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 its values?


const int foo = 10;
int bar = foo; <-- error: initializer element is not constant

const int foo = 10;

does not mean foo is a constant, it means the compiler will not allow you
to assign a value to foo other than an initializer. You need a real
constant, not a const variable.

--
- Mark ->
--
Nov 13 '05 #2

P: n/a
In article <41*************************@posting.google.com> , Mantorok Redgormor wrote:
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 its values?


In ISO/IEC 9899:1990 the "Constraints" subsection of the
"6.5.7 Initialization" section contains the sentence:

All the expressions in an initializer for an object that has
static storage duration or in an initializer list for an object
that has aggregate or union type shall be constant
expression.
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.