mop
October 4th, 2002, 06:54 AM
I'm at a lost on why the sizeof NODE per call below is 8.
My thoughts are it should be 5. considering the sizeof NODESTATE is 4 and the sizeof unsigned char is 1. Why is it 8?
# include <iostream>
using namespace std;
typedef enum
{
NOT_PRESENT = 0u,
POWER_OFF,
POWER_ON,
SILENT
} NODESTATE;
typedef struct
{
unsigned char address;
NODESTATE state;
} NODE;
static NODE NodeMap [] =
{
0, NOT_PRESENT,
0, NOT_PRESENT
// 0, NOT_PRESENT
};
int main(void)
{
printf( "%s%d\n", "sizeof NodeMap = ", sizeof(NodeMap));
printf( "%s%d\n", "sizeof NODE = ", sizeof(NODE));
printf( "%s%d\n", "sizeof unsigned char = ", sizeof(unsigned char));
printf("%d\n",sizeof(NODESTATE));
return 0;
}
RESULT :
sizeof NodeMap = 16
sizeof NODE = 8
sizeof unsigned char = 1
4
My thoughts are it should be 5. considering the sizeof NODESTATE is 4 and the sizeof unsigned char is 1. Why is it 8?
# include <iostream>
using namespace std;
typedef enum
{
NOT_PRESENT = 0u,
POWER_OFF,
POWER_ON,
SILENT
} NODESTATE;
typedef struct
{
unsigned char address;
NODESTATE state;
} NODE;
static NODE NodeMap [] =
{
0, NOT_PRESENT,
0, NOT_PRESENT
// 0, NOT_PRESENT
};
int main(void)
{
printf( "%s%d\n", "sizeof NodeMap = ", sizeof(NodeMap));
printf( "%s%d\n", "sizeof NODE = ", sizeof(NODE));
printf( "%s%d\n", "sizeof unsigned char = ", sizeof(unsigned char));
printf("%d\n",sizeof(NODESTATE));
return 0;
}
RESULT :
sizeof NodeMap = 16
sizeof NODE = 8
sizeof unsigned char = 1
4