Casting pointers
Michael Illgner
fillg1 at uni-paderborn.de
Tue Oct 2 22:33:50 AEST 1990
in tim at maths.tcd.ie (Timothy Murphy) writes:
>I recently came across the following problem,
>when temporarily 'borrowing' od from Unix to Mac.
>Consider a program like this.
>#include <stdio.h>
>char *buf = "abc";
>main()
>{
> int *n = (int*) buf;
> printf("%d", *n);
>}
>Should this always work?
>On the Mac, with THINK C,
>it only works if buf has an even address.
>Otherwise it bombs out.
>Is that a bug, according to standard C?
>--
>Timothy Murphy
>e-mail: tim at maths.tcd.ie
I think it is a problem with the Macs 680X0 processor. Larger objects like
integer number are aligned at even addresses, and if they are accessed at
an odd address, the processor raises an exception.
|-----------------------------------------------------------------------------|
|It`s not dead, | Michael Illgner | email to |
|It justs smells funny ! | Theodorstr. 27 | |
| | 4790 Paderborn (Germany) | fillg1 at uni-paderborn.de |
|Life, Universe and all | 05251/26488 or 60-2331 | |
------------------------------------------------------------------------------|
More information about the Comp.std.c
mailing list