comp.lang.ada
 help / color / mirror / Atom feed
From: "Peter C. Chapin" <pcc482719@gmail.com>
Subject: Re: A curiosity...
Date: Fri, 05 Dec 2008 06:51:53 -0500
Date: 2008-12-05T06:51:53-05:00	[thread overview]
Message-ID: <493915da$0$21338$4d3efbfe@news.sover.net> (raw)
In-Reply-To: <87r64naw36.fsf@willow.rfc1149.net>

Samuel Tardieu wrote:

> Nah, this is a FUD. If you want to use an integer type in C which is
> compatible with addresses, you should use "size_t" explicitely, not
> any other integer type (though I know of no architecture where
> "unsigned long" is not the same as "size_t" even though this is
> allowed).

Section 17.18.1.4 of the C99 standard defines the type intptr_t and
uintptr_t as follows:

<QUOTE>
The following type 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:

intptr_t

The following type designates an unsigned 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:

uintptr_t

These types are optional.
</QUOTE>

These types were introduced, I expect, because so many people feel a
need to convert pointers into integers and back again, yet the older C
standard did not provide a portable way of doing that. Note, however,
that these types are optional. Note also that the OP's example actually
requires the opposite of what is provided here. The OP's example depends
on converting an integer to a pointer and back again without loss of
information... the types above might not support that (they might be too
long to fit into a pointer).

Peter



  reply	other threads:[~2008-12-05 11:51 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-04 20:47 A curiosity mockturtle
2008-12-04 21:17 ` Adam Beneschan
2008-12-04 21:48   ` Hyman Rosen
2008-12-04 22:04     ` Ludovic Brenta
2008-12-04 22:10       ` Ludovic Brenta
2008-12-04 22:24         ` Hyman Rosen
2008-12-05  8:02         ` Samuel Tardieu
2008-12-05 11:51           ` Peter C. Chapin [this message]
2008-12-05 13:09           ` Martin Krischik
2008-12-05 15:15             ` Hyman Rosen
2008-12-06 13:26             ` Peter C. Chapin
2008-12-05 16:37           ` Keith Thompson
2008-12-04 22:19       ` Hyman Rosen
2008-12-05  9:03       ` Georg Bauhaus
2008-12-04 22:30 ` Randy Brukardt
2008-12-04 22:57   ` Hyman Rosen
2008-12-05 16:42     ` Keith Thompson
2008-12-05 16:57       ` Hyman Rosen
2008-12-05 20:20         ` Keith Thompson
2008-12-05 20:59           ` Adam Beneschan
2008-12-06 22:53             ` Hyman Rosen
2008-12-06 23:15               ` Gary Scott
2008-12-08 15:39                 ` Hyman Rosen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox