473,386 Members | 1,817 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,386 software developers and data experts.

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 1494

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Ben | last post by:
For many times, I've found myself changing my member variables from const back to non-const. No matter how good the original objective was, there was always at least one reason not to use const...
3
by: Zeng Dinghao | last post by:
char c = 'd'; const char cc = 'd'; char* pc = "dfdfdf"; const char* pcc = "dfdfdf"; char const* cpc = "dfdf"; cout << typeid(c).name() << endl; cout << typeid(cc).name() << endl; cout <<...
4
by: Pelle Beckman | last post by:
Hi, I saw this code in an earlier post (not that there's anything wrong with it) #include <iostream> using std::cout; const int hour = 3600; const int min = 60;
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: Chris | last post by:
Hi, can you define const-functions in C# as in C++ ? for example (C++-code) : int Cube :: GetSide() const { return m_side; }
1
by: Stabiplan BV | last post by:
Hi, I am trying to find const variables outside a class. Thur far I did not succeed. Without const, the variable is found but with const not. So, how can I get hold on global const variables...
4
by: Rui.Hu719 | last post by:
Hi, All: I read the following passage from a book: "There are three exceptions to the rule that headers should not contain definitions: classes, const objects whose value is known at compile...
3
by: sam_cit | last post by:
Hi Everyone, When a variable is declared as const, it is initialized along with the declaration, as modification later on is not possible. Having seen that, how about const variables in a class?...
23
by: Kira Yamato | last post by:
It is erroneous to think that const objects will have constant behaviors too. Consider the following snip of code: class Person { public: Person(); string get_name() const
10
by: Stephen Howe | last post by:
Hi Just going over some grey areas in my knowledge in C++: 1) If I have const int SomeConst = 1; in a header file, it is global, and it is included in multiple translations units, but it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.