Casting pointers

Timothy Murphy tim at maths.tcd.ie
Sun Sep 30 06:11:44 AEST 1990


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



More information about the Comp.std.c mailing list