Pointers and addresses

Mike Shepherd shepherd at mentor.cc.purdue.edu
Tue Oct 30 16:02:43 AEST 1990


In article <4139 at goanna.cs.rmit.oz.au> ok at goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
>In article <15831 at mentor.cc.purdue.edu>,
>  shepherd at mentor.cc.purdue.edu (Mike Shepherd) writes:
>> Is there a way to change an integer into an address location, vice versa, an
>> address location into an integer?
>
>What on earth is an address location?  Do you mean a pointer?
>How about an example of what you want to do?
>
>(I thought Purdue was supposed to be one of the really good places for
>Comp Sci.  Surely there must be _someone_ there who can give you face-
>to-face help?  That's bound to be better than the Net.)

	Well, someone apparently did know what I was talking about because
someone DID give me help from the Net.  And it worked out very
well...here is what they wrote (and in a very nice and creative way if I
might add) in case others of you are interested. And thanks again Xing! ...

----------------------------------------------------------

Subject: Re: Pointers and addresses
Newsgroups: comp.lang.c
In-Reply-To: <15831 at mentor.cc.purdue.edu>
Organization: Marquette University - Milwaukee, Wisconsin
Message-Id: <9010292031.AA08370 at compsys.mu.edu>
Date: 29 Oct 90 20:31:59 CST (Mon)
From: wuxing at comp.mscs.mu.edu (Xing Wu)
Status: OR

In article <15831 at mentor.cc.purdue.edu> you write:
>Is there a way to change an integer into an address location, vice versa, an
>address location into an integer?
>I keep getting illegal indirection & illegal pointer/integer comb errors.
>Is this possible?

This is just the compiler's way of saying "You know that it's just 32 bits,
and I know that it's just 32 bits, but I'm clever enough to know that it's
a *different type* of 32 bits."

The thing to do is to use a "cast":

char *s;
int i;

i = (int)s;
s = (char *)i;

etc.

A cast is your way of saying "I'm clever enough to know that you're clever
enough to know that it's a different type of 32 bits, so in your face."

As I always say, "strong typing is for weak minds."

----------------------------------------------------------

And thanks again Xing...it worked perfect!


Mike
-- 
|   Mike Shepherd	(shepherd at mentor.cc.purdue.edu)			      |
|-----------------------------------------------------------------------------|
| Sometimes I think the surest sign that intelligent life exists elsewhere in |
| the universe is that none of it has tried to contact us.    --Calvin of C&H |



More information about the Comp.lang.c mailing list