>> Any pointer type may be converted to an integer type. Except as previously specified, the
>> result is implementation-defined. If the result cannot be represented in the integer type,
>> the behavior is undefined. The result need not be in the range of values of any integer
>> type
Thanks
Yes. Consider sizeof(void*) > sizeof(int), for example.
> Can the mapping function be a function of time?
That would be weird, but I see nothing in the Standard
to forbid it.
>>> Any pointer type may be converted to an integer type. Except as previously specified, the
>>> result is implementation-defined. If the result cannot be represented in the integer type,
>>> the behavior is undefined. The result need not be in the range of values of any integer
>>> type
The phrase "implementation-defined" means only as much as
it says. It does not mean "implementation-defined, subject to
restrictions A,B,C,..."
--
Eric Sosman
eso...@ieee-dot-org.invalid
Yes, except in the case where a pointer to void is converted to an
integer value is of type intprt_t or uintptr_t, in which case the
conversion is required to be reversible (7.18.1.4).
> Can the mapping function be a function of time?
In general, the standard doesn't say anything to prevent it. In those
special cases where the conversion is required to be reversible (see
above), time-dependence is still allowed, but is constrained by the
reversibility requirement: the same pointer may convert to different
integer values at different times, but all of those different integer
values must convert back to a pointer which compares equal to the
original, regardless of when they are converted back.
Not so weird.
As an example, the 68000 architecture had 32 bits wide address registers but
only 24 physical addressing lines, so that, the upper 8 bits of 32 bits
pointers were ignored.
I know that many programs used these extra bits to store additionnal data
"attached" to the pointer (bad practice IMO).
Later, when 68030 CPU gave a larger address space, these programs could not
be loaded above a 16 MiB upper bound. Those programs were said not to be "32
bits clean".
I think a conforming implementation on 68000 could have defined 32 bits
pointers with 8 padding bits, and provided an extension
__read_extra_pointer_data(void*)/__write_extra_pointer_data(void*,unsigned
char) to manipulate these padding bits.
A void* -> unsigned long conversion would keep these padding bits, as
zero-ing them out would reduce performances and loose data.
Then, it would be possible to get:
p1 == p2 && ((unsigned long)p1) != ((unsigned long)p2)
I don't know if such an implementation did exist.
Basically, any platform with padding bits in pointers may get this behavior.
--
Andr� Gillibert