🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: pointer casting

#2620
From: Joachim Huober
Date: Thu, 18 Apr 1996 12:38
33 lines
2438 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? I played with such conversions on Sun Sparcstation
|> (which surely requires proper allignment of data with sizeof > 1),
|> using both Sun compiler v. 2.0.1 and Gnu 2.6.3, but never observed
|> such an automatic adjustment? Odd pointers casted to (e.g.) double
|> result in Bus Error when referenced. And they show the same odd value
|> when printed as long values.
As far as I know, this problem is more academic. It is allowed for an
operating system, to store pointers differently (according to their type).
So a (char *) might use 35bits, wheres (double *) uses only 30 bits. If
this is the case, a cast from (char *) to (double *) and back to (char *)
(through a void pointer or not) strips 5 bits. 
I've never seen an operating system, which does use different pointers
for different objects, thats why normaly typecasting is just a runtime
problem when derefferencing the pointer. (See your core dump).
|> 
|> So I wonder whether this adjustment is just (nowhere-implemented) possibility 
|> or some real thing?

Joachim
-- 
---------------------------------------------------------------------
Joachim Huober                                Phone: +49 731 502-6241
UDINE-Project,            URZ, University of Ulm, 89081 Ulm , Germany
E-mail: joachim.huober@rz.uni-ulm.de 
---------------------------------------------------------------------
Technical Details
Message-ID: <4l5d3d$23f@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: huober_j@spica.rz.uni-ulm.de (Joachim Huober)
Newsgroups: comp.lang.c.moderated
Subject: Re: pointer casting
Date: 18 Apr 1996 07:38:05 -0500
Organization: Universitaet Ulm
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4l5d3d$23f@solutions.solon.com>
References: <4l33mf$7pr@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com