Assigning an address to an integer

Henry Spencer henry at utzoo.uucp
Sat Jun 2 03:00:16 AEST 1990


In article <1280003 at hpcc01.HP.COM> azarian at hpcc01.HP.COM (Randy Azarian) writes:
>Can I assign an address of a variable to the value of a standard integer?

Any sensible compiler will reject this as a type mismatch.  The address of
a variable of type T is of type "pointer to T".  This is not an integer
type, and cannot be assigned to an integer variable.

If you know what you are doing, the correct way to accomplish this is by
casting the address to an integer type:

	i = (int) &x;

The result of this is very implementation-specific and you need to know
what your compiler is going to do about it.
-- 
As a user I'll take speed over|     Henry Spencer at U of Toronto Zoology
features any day. -A.Tanenbaum| uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list