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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date