Why are enum const values accessible outside the block in which the enum is defined?
-
struct tagged_union { enum {INT, FLOAT, STRING} type; int integer; float floating_point; char *string; } tu; /* Why INT accessible here? */ tu.type = INT; tu.integer = 100;
-
Answer:
You tagged this with both C++ and C, but that "INT" is only accessible in C. In a C++ program, INT is a member of tagged_union and you would have to write tu.type = tu.INT; or tu.type=tagged_union::INT; In a C program, INT is an enumerator constant whose scope is the block scope in which the tagged_union's declaration is located. There simply isn't a struct scope in C and enumerators are not struct members in C.
Sergey Zubkov at Quora Visit the source
Related Q & A:
- Why is my cat suddenly urinating outside of the litter box?Best solution by Yahoo! Answers
- Why doesn't Disney Channel have outside commercials?Best solution by Yahoo! Answers
- Which New Kid on the Block was your favorite...and is he still the best?Best solution by Yahoo! Answers
- What are intrinsic values and why are they meaningful?Best solution by Quora
- Why do we have to pee more often when it's cold outside?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.