@anand....regarding problem 2 i agree with you and observed the same....but
that gives me the feel that the compiler in working in the interprating
manner though it doesn't.......btw thanks for pointing it out.....

and in problem 3 what i understood after reading with what you wrote is that
size of tag will remain sizeof(int) irrespective of the number of constants
in it.....correct me if i am wrong !!
On Tue, Jul 12, 2011 at 2:20 PM, Anand Saha <[email protected]> wrote:

>
> On Tue, Jul 12, 2011 at 1:29 AM, nicks <[email protected]> wrote:
>
>>
>> *PROBLEM 3>.*
>> *
>> *
>> #include<stdio.h>
>> main()
>> {
>> enum {low='a',high='b'}tag;
>>  char try=low;
>> printf("Size=%d",sizeof(tag));
>> switch (try)
>>  {
>> case 'a':printf("aaa");break;
>> case 'b':printf("bbb");
>>  case 'c':printf("ccc");
>> }
>> //system("pause");
>> }
>>
>> in this program size of enum comes out to be 4..help me in understanding
>> the size of enum...how it is stored in memory??...does the size of enum
>> depend on number of constant in it ?....anyone link regarding that ??
>>
>>
>
> What will be interesting to see here is:
>
> printf 
> <http://www.opengroup.org/onlinepubs/009695399/functions/printf.html>("Size = 
> %d\n",sizeof(tag));printf 
> <http://www.opengroup.org/onlinepubs/009695399/functions/printf.html>("Size = 
> %d\n",sizeof(low));
>
>
> We will get 4 and 4.  'tag' is the optional identifier, 'low' is an
> enumerated type.
>
> From C99,
>
> for tag: "The expression that defines the value of an enumeration constant
> shall be an integer constant expression that has a value representable as an
> int."
>
> for low: "Each enumerated type shall be compatible with char, a signed
> integer type, or an unsigned integer type. The choice of type is
> implementation-defined, but shall be capable of representing the values of
> all the members of the enumeration. The enumerated type is incomplete until
> after the } that terminates the list of enumerator declarations."
>
> PS: I didn't know the exact constraints too, thanks to nicks for bringing
> up this question.
> --
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to