enum question

J

Joe Van Dyk

I have some code like:

typedef enum
{
First = 0,
Second,
Third,
Fourth,
} Something;

Can the "= 0" part on the first value be safely removed? I believe it
can -- just want to confirm.

Thanks,
Joe
 
R

ramu

Joe said:
I have some code like:

typedef enum
{
First = 0,
Second,
Third,
Fourth,
} Something;

Can the "= 0" part on the first value be safely removed? I believe it
can -- just want to confirm.

Thanks,
Joe
 
J

jaysome

I have some code like:

typedef enum
{
First = 0,
Second,
Third,
Fourth,
} Something;

Can the "= 0" part on the first value be safely removed? I believe it
can -- just want to confirm.

Yes. Guaranteed by the standard.

In fact, you can remove it and even do stuff like this:

int *ptr = NULL;
/* some lines later */
if ( ptr == First ) /* if ptr is NULL */

Altough legal, don't do that. Do this instead:

if ( !ptr )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top