Assigning an address to an integer

Dion Hollenbeck hollen at megatek.UUCP
Sat Jun 2 05:16:34 AEST 1990


>From article <1280003 at hpcc01.HP.COM>, by azarian at hpcc01.HP.COM (Randy Azarian):
> Can I assign an address of a variable to the value of a standard integer?
> {
>   int a,d;
>   a=&d;
>   bdos(1,a,1);
> }
> This works, but gives me the following warning:
>   warning C4047: '=' : different levels of indirection


You can get rid of the problem by casting it:

   a = (int)&d ;

We do this all the time when passing addresses as "magic cookies".
We obtain them and do the cast.  They are then stored as ints and
passed around as ints.  When they finally get to the function
which needs them, they are cast back to a pointer of the proper
type.

-- 
	Dion Hollenbeck             (619) 455-5590 x2814
	Megatek Corporation, 9645 Scranton Road, San Diego, CA  92121

        uunet!megatek!hollen       or  hollen at megatek.uucp



More information about the Comp.lang.c mailing list