Is there a HOST_BITS_PER_POINTER macro?

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Sat Feb 7 13:09:00 GMT 1998


 > From: Richard Henderson <rth@dot.cygnus.com>
 > 
 > The problem is that it is implementation defined what
 > format pointers are represented in.  So you might easily
 > get any of
 > 
 > 	0
 > 	00000000
 > 	0x0
 > 	0x00000000
 > 	0000:0000
 > 
 > I can think of two possible solutions:
 > 
 > [...]
 > 
 > or 
 > 	
 > 	char buf[64];
 > 	char *p = buf, *q = NULL;
 > 	sprintf(buf, "%p", p);
 > 	sscanf(buf, "%p", &q);
 > 	exit (p != q);
 > 
 > if sscanf can be trusted to read them back in.  I would think that's
 > required, but...
 > r~

	I like your second solution better.  If sscanf doesn't work,
gcc will fall back on the definitions in machmode.h.  Here's a patch
to implement this.  If you think its okay, would you please install it?

		Thanks,
		--Kaveh


Sat Feb  7 15:11:28 1998  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

        * aclocal.m4 (GCC_FUNC_PRINTF_PTR): New macro to test the printf
        functions for whether they support the %p format specifier.

        * acconfig.h (HOST_PTR_PRINTF): Insert stub for autoconf.

        * configure.in (GCC_FUNC_PRINTF_PTR): Use it.


diff -r -u orig/egcs-980205/gcc/acconfig.h egcs-980205/gcc/acconfig.h
--- orig/egcs-980205/gcc/acconfig.h	Sat Jan 31 19:48:00 1998
+++ egcs-980205/gcc/acconfig.h	Sat Feb  7 14:27:17 1998
@@ -1,3 +1,6 @@
+/* Define to "%p" if printf supports it, else machmode.h will define it.  */
+#undef HOST_PTR_PRINTF
+
 /* Define if your cpp understands the stringify operator.  */
 #undef HAVE_CPP_STRINGIFY
 
diff -r -u orig/egcs-980205/gcc/aclocal.m4 egcs-980205/gcc/aclocal.m4
--- orig/egcs-980205/gcc/aclocal.m4	Sat Jan 31 19:48:01 1998
+++ egcs-980205/gcc/aclocal.m4	Sat Feb  7 14:33:34 1998
@@ -42,6 +42,27 @@
 done
 ])
 
+dnl See if the printf functions in libc support %p in format strings.
+AC_DEFUN(GCC_FUNC_PRINTF_PTR,
+[AC_CACHE_CHECK(whether the printf functions support %p,
+  gcc_cv_func_printf_ptr,
+[AC_TRY_RUN([#include <stdio.h>
+
+main()
+{
+  char buf[64];
+  char *p = buf, *q = NULL;
+  sprintf(buf, "%p", p);
+  sscanf(buf, "%p", &q);
+  exit (p != q);
+}], gcc_cv_func_printf_ptr=yes, gcc_cv_func_printf_ptr=no,
+	gcc_cv_func_printf_ptr=no)
+rm -f core core.* *.core])
+if test $gcc_cv_func_printf_ptr = yes ; then
+  AC_DEFINE(HOST_PTR_PRINTF, "%p")
+fi
+])
+
 dnl See if symbolic links work and if not, try to substitute either hard links or simple copy.
 AC_DEFUN(GCC_PROG_LN_S,
 [AC_MSG_CHECKING(whether ln -s works)
diff -r -u orig/egcs-980205/gcc/configure.in egcs-980205/gcc/configure.in
--- orig/egcs-980205/gcc/configure.in	Sat Jan 31 19:48:05 1998
+++ egcs-980205/gcc/configure.in	Sat Feb  7 14:25:13 1998
@@ -180,6 +180,8 @@
 AC_CHECK_FUNCS(strtoul bsearch strerror putenv popen vprintf bcopy bzero bcmp \
 	index rindex kill getrlimit setrlimit atoll atoq)
 
+GCC_FUNC_PRINTF_PTR
+
 GCC_NEED_DECLARATIONS(malloc realloc calloc free bcopy bzero bcmp \
 	index rindex getenv atol sbrk abort)
 
--
Kaveh R. Ghazi			Project Manager / Custom Development
ghazi@caip.rutgers.edu		ICon CMT Corp.



More information about the Gcc mailing list