China Blue Veins
5/11/2011 1:47:00 PM
In article <slrnisl271.p2s.fis@iris.zem.fi>,
Heikki Kallasjoki <see@end.of.message.invalid> wrote:
> On 2011-05-11, Columbus sailed the ocean China Blue <chine.bleu@yahoo.com>
> wrote:
> > In article
> > <80905e4d-6b11-4843-b4e7-96f0c7db8b23@l18g2000yql.googlegroups.com>,
> > pozz <pozzugno@gmail.com> wrote:
> >
> >> What do you think about this code?
> >
> > stdint.h defines a type name intptr_t which is an integer that can be
> > converted
> > to a pointer and back again:
> > void *p = ...; intptr_t a = ...;
> >
> > a is an integer variable and you can use << >> % etc with it.
> >
> > (void*)(intptr_t)p == p
> > (intptr_t)(void*)a == a
>
> The above is not entirely true. The intptr_t and uintptr_t types, if
> they exist (they are optional), are capable of holding any valid
> pointer-to-void value, but not the other way around. To quote the
> C99 draft,
>
> "The following type [intptr_t] designates a signed integer type with the
> property that any valid pointer to void can be converted to this type,
> then converted back to pointer to void, and the result will compare
> equal to the original pointer"
>
> In other words, the conversion to intptr_t and back is safe only for
> valid pointers. Arbitrary integer values, even if they are stored in an
> intptr_t object, are not guaranteed to be safely convertible to
> pointers.
That's nice. Any compiler that screws this up will break so much software that
it will be rejected.
--
Damn the living - It's a lovely life. I'm whoever you want me to be.
Silver silverware - Where is the love? At least I can stay in character.
Oval swimming pool - Where is the love? Annoying Usenet one post at a time.
Damn the living - It's a lovely life. In 1492....