C9201002: Default Struct Alignment May Fail with /Gtin C

ID Number: Q79820

6.00 6.00a 6.00ax | 6.00 6.00a

MS-DOS | OS/2

buglist6.00 buglist6.00a buglist6.00ax fixlist7.00

Summary:

PROBLEM ID: C9201002

SYMPTOMS

In the Microsoft C Compiler versions 6.0, 6.0a, and 6.0ax,

structures are aligned on an even byte boundary by default. Under

the following conditions, a structure will begin on an odd byte

boundary even though the default has not been overridden through

either the /Zp option or the pack pragma:

1. The structure is declared with the static qualifier.

2. There is an odd number of odd length strings.

3. Compile options include /AL and /Gt[num] where [num] has a

value from 0 to the structure length.

RESOLUTION

Remove the static qualifier.

-or-

Increase the [num] in /Gt[num] so that it is greater than the

length of the structure.

-or -

Make sure that there is an even number of odd length strings.

STATUS

Microsoft has confirmed this to be a problem in C versions 6.0,

6.0a, and 6.0ax. This problem was corrected in C version 7.0.

More Information:

The following example illustrates the problem. The address of the

structure x will be odd even though structures should be aligned on

an even byte boundary by default.

Sample Code

-----------

/* Compile options needed: /AL /Gt[num] (where [num] is 0-6)

*/

#include <stdio.h>

typedef struct

{

unsigned short x1;

unsigned short x2;

unsigned short x3;

}node; // sizeof struct node is 6

static node x; // uninitialized static struct

char *string = "12"; // odd length when \0 is counted

void main( )

{

printf( "Address of x: %p\n", &x );

}

Additional reference words: 6.00 6.00a 6.00ax