From: Alan Rotnemer <73765.1577@CompuServe.COM>
Subject: Re: isalign option on cxx?
Date: 1996/02/28 [thread overview]
Message-ID: <4h0d1s$cp3$1@mhade.production.compuserve.com> (raw)
In-Reply-To: 4gkea1$5fm@zk2nws.zko.dec.com
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
prev parent reply other threads:[~1996-02-28 5:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-02-23 5:00 isalign option on cxx? Alan Rotnemer
1996-02-23 5:00 ` Tom Carlson
1996-02-28 5:00 ` Alan Rotnemer [this message]
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox