Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Advanced
Oct 23, 2000

Uninitialized enum Variables

The value of an uninitialized automatic enum variable is indeterminate. Uninitialized global and static enum variables have a zero value by default. In this regard, enum variables are similar to fundamental types such as int and char. However, unlike int and char, an uninitialized enum might have a value that is beyond the range of its enumerators. In the following example, the global enum variable st is initialized to zero. Yet none of Stat's enumerators equals zero. Therefore, using st before assigning a valid value to it results unpredictable behavior:

 
enum Stat {good=1, bad=2}; // no enumerator equals zero
Stat st; // bad, initialized to 0 by default
int main()
{
 if(st==good) //always false
 //
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date