V
Vijay Kumar R Zanvar
Hi c.l.c,
The following table show the general structure
of a header:
Byte # Field Description
------ -----------------
0 Extended message flag (01H)
1 Extended message length (n)
2 Extended message code
3-(n+1) Optional arguments
Multibyte fields are specified in big-endian order.
Now, I can declare the structures in two ways:
struct header_1 {
unsigned char flag;
unsigned char len;
unsigned char code;
char *arg;
};
and,
/* 32-bit m/c. i.e., sizeof (int) == 4 */
struct header_2 {
unsigned int flag : CHAR_BIT;
unsigned int len : CHAR_BIT;
unsigned int code : CHAR_BIT;
char *arg;
};
My major concern are padding, sizeof the structures and
speed of execution. Are the two structures the same in this
regard?
The following table show the general structure
of a header:
Byte # Field Description
------ -----------------
0 Extended message flag (01H)
1 Extended message length (n)
2 Extended message code
3-(n+1) Optional arguments
Multibyte fields are specified in big-endian order.
Now, I can declare the structures in two ways:
struct header_1 {
unsigned char flag;
unsigned char len;
unsigned char code;
char *arg;
};
and,
/* 32-bit m/c. i.e., sizeof (int) == 4 */
struct header_2 {
unsigned int flag : CHAR_BIT;
unsigned int len : CHAR_BIT;
unsigned int code : CHAR_BIT;
char *arg;
};
My major concern are padding, sizeof the structures and
speed of execution. Are the two structures the same in this
regard?