Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!rochester!rit!cci632!ccicpg!felix!asylvain From: asylvain@felix.UUCP (Alvin E. Sylvain) Newsgroups: comp.std.c Subject: Re: Casting pointers Keywords: Pointers, casting Message-ID: <151966@felix.UUCP> Date: 4 Oct 90 18:58:28 GMT References: <1990Sep29.201144.23113@maths.tcd.ie> Sender: daemon@felix.UUCP Reply-To: asylvain@felix.UUCP (Alvin E. Sylvain) Organization: FileNet Corp., Costa Mesa, CA Lines: 36 In article <1990Sep29.201144.23113@maths.tcd.ie> tim@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 >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? I don't know off-hand what the "right" answer is to this one, but I personally lump this kind of problem into the following category: Patient, demonstrating a painful maneuver: "Doc, it hurts when I do dat." Doctor, repeating same maneuver: "Don't do dat!" Put another way, unless you can convince me you have compelling reasons to cast a character pointer into an integer pointer, then treat it like a character pointer, "don't do dat!" Change the "int *n" to "char *n", and let it go at that. -- =======================Standard Disclaimers Apply======================= "We're sorry, but the reality you have dialed is no | Alvin longer in service. Please check the value of pi, | "the Chipmunk" or pray to your local diety for assistance." | Sylvain