* Re: isalign option on cxx?
1996-02-23 5:00 ` Tom Carlson
@ 1996-02-28 5:00 ` Alan Rotnemer
0 siblings, 0 replies; 3+ messages in thread
From: Alan Rotnemer @ 1996-02-28 5:00 UTC (permalink / raw)
Tom:
Thank you for your reply to my question regarding the "isalign"
option.
I wonder if you would be familiar with the following problem I
recently ran into while porting code from another UNIX platform.
The code that I listed below yields different results from the
"cc" and "cxx" compilers (no compiler options). It seems that
the cxx compiler has a problem with a pointer reference to
the unsigned short within a struct when the field is not on
an even boundary and the structure is packed. "cc" works OK.
Is this a bug in cxx?
Thanks again.
Alan Rotnemer
#include <stdio.h>
#include<stdlib.h>
#pragma pack 1
struct aa
{
char cc1[7] ;
unsigned short us ;
};
struct aa xaa;
void main()
{
struct aa *pxaa, *pxaa1, *pxaa2;
pxaa = &xaa;
xaa.us = (unsigned short ) 299;
printf("size of aa struct is %u\n", sizeof(struct aa));
printf ("dot non-calloc 299 moved to %u\n", xaa.us);
printf ("...but using ptr ref its is %u\n", pxaa->us);
printf("...hex is ptr: %x, dot: %x \n", pxaa->us, xaa.us);
pxaa->us = (unsigned short ) 299;
printf ("pointer non-calloc 299 moved to %u\n",
pxaa->us);
printf ("....but using dot ref it is %u\n", xaa.us);
pxaa1 = (struct aa *) calloc(1, sizeof(struct aa));
pxaa1->us = 299;
printf ("calloc ptr ref 299 moved to %u\n",
pxaa1->us);
}
#pragma pack 8
***************************************************************************
on cc compiler I get ...
size of aa struct is 9
dot non-calloc 299 moved to 299
..but using ptr ref its is 299
..hex is ptr: 12b, dot: 12b
pointer non-calloc 299 moved to 299
...but using dot ref it is 299
calloc ptr ref 299 moved to 299
****************************************************************************
on cxx compiler I get..
size of aa struct is 9
dot non-calloc 299 moved to 299
..but using ptr ref its is 43
..hex is ptr: 2b, dot: 12b
pointer non-calloc 299 moved to 43
...but using dot ref it is 299
calloc ptr ref 299 moved to 43
^ permalink raw reply [flat|nested] 3+ messages in thread