Article View: comp.std.c
Article #1762Casting pointers
From: Timothy Murphy
Date: Sat, 29 Sep 1990 20:11
Date: Sat, 29 Sep 1990 20:11
25 lines
899 bytes
899 bytes
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@maths.tcd.ie
Technical Details
Message-ID:
<1990Sep29.201144.23113@maths.tcd.ie>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!uunet!mcsun!ukc!tcdcs!swift.cs.tcd.ie!maths.tcd.ie!timShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!uunet!mcsun!ukc!tcdcs!swift.cs.tcd.ie!maths.tcd.ie!tim From: tim@maths.tcd.ie (Timothy Murphy) Newsgroups: comp.std.c Subject: Casting pointers Summary: Can a char* always be cast as an int* Keywords: Pointers, casting Message-ID: <1990Sep29.201144.23113@maths.tcd.ie> Date: 29 Sep 90 20:11:44 GMT Organization: Dept. of Maths, Trinity College, Dublin, Ireland. Lines: 25