🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2618

Re: pointer casting

#2618
From: William Kaufman
Date: Thu, 18 Apr 1996 12:37
31 lines
2121 bytes
In article <4l33mf$7pr@solutions.solon.com> msz@sirius.astrouw.edu.pl (Michal Szymanski) writes:
] There is a discussion of (void *) and pointer casting going on this list.
] K&R "Ansi C" book says that conversion: (type *) -> (void *) -> (type *)
] is guaranteed to yield the same pointer. This (and the discussion on the
] list) suggests that another chain: (void *) -> (type *) -> (void *)
] might result in some change of the original pointer. In other words
] I would guess that casting a void pointer to a pointer to a type requiring
] special memory allignment might involve adjusting it to a proper value.
] Is this true?

    An implementation is free to modify pointers to obey alignment
restrictions: on a Sun, your compiler _could_ round an odd pointer off
to the nearest alignment.  No compilers I know of actually do, though:
crashing is sometimes a more obvious complaint than just accessing the
wrong section of memory,...

    However, I _do_ know of at least one machine where the pointer can
get modified--not because of different alignments, but because of
different binary representations for pointers.  The compiler can and
does lose bits off a pointer if you cast to a pointer type with the
wrong binary representation (i.e., from (void *) or (char *) to anything
else).

    (And, no, I'm not going to say which--I want you to stay paranoid,
producing portable code.)

                                           -- Bill K.

Bill Kaufman               | "I grow old, I grow old, I shall wear the bottom
wkaufman@us.oracle.com     |  of my trousers rolled,..."
                           |     -- the Mole-Man, "Incredible Hulk" annual
Technical Details
Message-ID: <4l5d1v$22g@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4l33mf$7pr@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: wkaufman@us.oracle.com (William Kaufman)
Newsgroups: comp.lang.c.moderated
Subject: Re: pointer casting
Date: 18 Apr 1996 07:37:18 -0500
Organization: Oracle Corporation, Redwood Shores CA
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4l5d1v$22g@solutions.solon.com>
References: <4l33mf$7pr@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com