[libstdc++] intptr_t usage
Jakub Jelinek
jakub@redhat.com
Fri Mar 30 19:06:00 GMT 2007
On Fri, Mar 30, 2007 at 08:14:55PM +0200, Paolo Carlini wrote:
> Mark Mitchell wrote:
>
> >How about adding __INTPTR_TYPE__ to the builtin defines, like
> >__SIZE_TYPE__ and __PTRDIFF_TYPE__?
> >
> Something like the below? If you find it reasonable I can to add to it a
> couple of lines of docs and use it in the library.
As stdint.h is provided by the various OSes, doing this is risky, you might
very well define __INTPTR_TYPE__ or __UINTPTR_TYPE__ to a type that has the
same precision as the real intptr_t or uintptr_t, but mangles differently.
For glibc this happens to be the same:
/* Types for `void *' pointers. */
#if __WORDSIZE == 64
# ifndef __intptr_t_defined
typedef long int intptr_t;
# define __intptr_t_defined
# endif
typedef unsigned long int uintptr_t;
#else
# ifndef __intptr_t_defined
typedef int intptr_t;
# define __intptr_t_defined
# endif
typedef unsigned int uintptr_t;
#endif
which is int on ILP32 and long on LP64 the same as int with pointer mode.
But it wouldn't surprise me if e.g. other OSes define intptr_t always to
long etc.
IMHO it is far better to just use int __attribute__((__mode__ (__pointer__)))
in libstdc++ headers and don't suggest that it is necessarily the same type
as intptr_t or uintptr_t.
> @@ -396,6 +395,11 @@
> else
> gcc_unreachable ();
> builtin_define_type_max ("__INTMAX_MAX__", intmax_type_node, intmax_long);
> +
> + builtin_define_with_value ("__INTPTR_TYPE__", "int __attribute__ "
> + "((__mode__ (__pointer__)))", 0);
> + builtin_define_with_value ("__UINTPTR_TYPE__", "unsigned int __attribute__ "
> + "((__mode__ (__pointer__)))", 0);
> }
>
> /* Hook that registers front end and target-specific built-ins. */
Jakub
More information about the Gcc-patches
mailing list