470,849 Members | 1,036 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Const variables

Hi,

is it valid (acc. to ANSI-C 99) to assign an uninitialized
const value a constant afterwards, like

const int constInt;
int main( void )
{
constInt = 10;
return 0;
}

Regards,
Chris
May 11 '06 #1
3 1416

Christian Christmann wrote:
Hi,

is it valid (acc. to ANSI-C 99) to assign an uninitialized
const value a constant afterwards, like

const int constInt;
int main( void )
{
constInt = 10;
return 0;
}


No, it is not. It is OK, however, to initialise it:

const int constInt = 10;

May 11 '06 #2
Christian Christmann <pl*****@yahoo.de> wrote:
is it valid (acc. to ANSI-C 99) to assign an uninitialized
const value a constant afterwards, like

const int constInt;
int main( void )
{
constInt = 10;
return 0;
}


No.

Richard
May 11 '06 #3
Richard Bos wrote:
Christian Christmann <pl*****@yahoo.de> wrote:
is it valid (acc. to ANSI-C 99) to assign an uninitialized
const value a constant afterwards, like

const int constInt;
int main( void )
{
constInt = 10;
return 0;
}


No.


Besides which it isn't even uninitialized. Being in static
storage, it has the value 0.

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
May 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

31 posts views Thread by Ben | last post: by
4 posts views Thread by Pelle Beckman | last post: by
16 posts views Thread by herbertF | last post: by
20 posts views Thread by Chris | last post: by
1 post views Thread by Stabiplan BV | last post: by
4 posts views Thread by Rui.Hu719 | last post: by
3 posts views Thread by sam_cit | last post: by
23 posts views Thread by Kira Yamato | last post: by
10 posts views Thread by Stephen Howe | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.