Anirudh <an*******@gmail.com> wrote:
Is there a way to get different return values for sizeof(int*) etc.
Right now, it is 4 on my machine...I want it to return, say, 3.
Write your own compiler;-)
Basically, I'd like to play around with alignment issues that might
arise with memory allocation if sizeof(int) != sizeof(int*).
There are easier way to do unaligned access than fiddling with the
compiler, e.g (untested and error checking omitted for obvious
reasons;-)
char *c = malloc( 2 * sizeof( int ) );
int i;
for ( i = 0; i < sizeof( int ); i++ )
{
* ( int * ) ( c + i ) = i;
print( "%d: %d\n", i, * ( int * ) ( c + i ) );
}
If this crashes with a bus error (or whatever it's called on your
system) you have a system that won't allow unaligned access. If it
does not crash te system the alternatives are either that unaligned
accesses are not flagged or that you have sizeof(int) == 1.
Regards, Jens
--
\ Jens Thoms Toerring ___
Je***********@physik.fu-berlin.de
\__________________________
http://www.toerring.de