As suggeted tried with -WC, -ei, its working now.
Thanks for your help. Also tried printing all the addresses
enum testswitch
4 {
5 TYPE1=0,
6 TYPE2,
7 TYPE3,
8 MAX_TYPES
9 };
10 typedef enum testswitch Switches;
11
12 void *ptr;
13
14 void main()
15 {
16 int val=0;
17 //testswitch switchtypes;
18 Switches switchtypes;
19 switchtypes = TYPE2;
20 printf(“sizeofenum:%ld\n”, sizeof(testswitch));
21 ptr = &switchtypes;
22 printf(“Sizes of: testswitch:%d, int:%d, longint:%d\n”,
sizeof(Switches)
23 printf(“Address in ptr:%u\n”, ptr);
24 printf(“Address of ptr:%u\n”, &ptr);
25 printf(“Value of *(int *)ptr:%d\n”, *((int *)
ptr));
26 printf(“Value of switchtypes:%d\n”, switchtypes);
27 printf(“Address of switchtypes:%u\n”,
&switchtypes);
28 printf(“Value in Address of switchtypes:%d\n”, *
(&switchtypes));
29 printf(“Address of (int *)ptr:%u\n”, (int *)ptr);
30 val = *((int *)ptr);
31 printf(“value:%d\n”,val);
32
33 }
sizeofenum:1
Sizes of: testswitch:1, int:4, longint:4
Address in ptr:40460
Address of ptr:50212
Value of *(int *)ptr:40449
Value of switchtypes:1
Address of switchtypes:40460
Value in Address of switchtypes:1
Address of (int *)ptr:40460
value:40449
This is the result without -WC,-ei option.
Below are the results with -WC, -ei option:-
sizeofenum:4
Sizes of: testswitch:4, int:4, longint:4
Address in ptr:40452
Address of ptr:50212
Value of *(int *)ptr:1
Value of switchtypes:1
Address of switchtypes:40452
Value in Address of switchtypes:1
Address of (int *)ptr:40452
value:1
How is cc different from wcc in QNX?
One more thing noticed, wrote a test program wherein
char c=‘A’;
int a;
float f ;
when the address was printed:
sizeof(char):1
ADdr of int :40456
ADdr of char c:40468
ADdr of char ch:40464
ADdr of float :40460
eventhough sizofchar is 1 byte, 4 bytes are allocated, as we can see that
ch:addr 40464 and c address 40468?
How this address are allocated? as per sizeof(char) one a single byte to
be allocated?
something wrong with my assumption, again!!
Thanks in advance,
Radha
Wojtek Lerch wrote:
“Mario Charest” postmaster@127.0.0.1 wrote in message
news:d5vi2o$rg5$> 1@inn.qnx.com> …
I’m check the old C++ standard (I don’t have the C or
lastest C++ available) and there is nothing in there that says that enum
is
of int size.
C99 6.7.2.2#4:
Each enumerated type shall be compatible with char, a signed integer type,
or an
unsigned integer type. The choice of type is implementation-defined,108) but
shall be
capable of representing the values of all the members of the enumeration.
- An implementation may delay the choice of which integer type until all
enumeration constants have
been seen.