* Re: Is there a HOST_BITS_PER_POINTER macro?
@ 1998-02-06 8:48 Kaveh R. Ghazi
1998-02-10 3:34 ` Richard Henderson
0 siblings, 1 reply; 8+ messages in thread
From: Kaveh R. Ghazi @ 1998-02-06 8:48 UTC (permalink / raw)
To: rth; +Cc: egcs
> From: Richard Henderson <rth@dot.cygnus.com>
>
> On Thu, Feb 05, 1998 at 07:45:09PM -0500, Kaveh R. Ghazi wrote:
> > I get a warning from "-W -Wall" which complains about int format vs
> > pointer argument. Is there a way to define a macro in machmode.h
> > which can cast the pointer to the appropriately sized integer type?
>
> Ideally you would use "%p" everywhere, but to support bootstrapping,
> we should probably autoconf a test for that.
> r~
Good point. I guess it would have to be a runtime check of the
*printf functions in libc. How about using code like this?
> #include <stdio.h>
> main()
> {
> char foo[30];
> char * ptr = (char *) 0;
>
> sprintf(foo, "%p", ptr)
> exit (strcmp(foo, "0"));
> }
and then doing AC_DEFINE(HOST_PTR_PRINTF, "%p") if it passes?
(machmode.h won't define it if its already defined.)
If you think the test is sufficient, I'll whip up a patch.
--Kaveh
--
Kaveh R. Ghazi Project Manager / Custom Development
ghazi@caip.rutgers.edu ICon CMT Corp.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is there a HOST_BITS_PER_POINTER macro?
1998-02-06 8:48 Is there a HOST_BITS_PER_POINTER macro? Kaveh R. Ghazi
@ 1998-02-10 3:34 ` Richard Henderson
0 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 1998-02-10 3:34 UTC (permalink / raw)
To: Kaveh R. Ghazi; +Cc: rth, egcs
On Fri, Feb 06, 1998 at 11:48:08AM -0500, Kaveh R. Ghazi wrote:
> > sprintf(foo, "%p", ptr)
> > exit (strcmp(foo, "0"));
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:
char buf[64];
sprintf (buf, "%p", buf);
#ifdef HAVE_INDEX
exit (index (buf, 'p') == NULL);
#else
exit (strchr (buf, 'p') == NULL);
#endif
since it seems unlikely that any representation will result in 'p',
though of course that's not the only failure mode, 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~
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is there a HOST_BITS_PER_POINTER macro?
1998-02-07 13:09 Kaveh R. Ghazi
@ 1998-02-07 13:29 ` Richard Henderson
0 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 1998-02-07 13:29 UTC (permalink / raw)
To: Kaveh R. Ghazi; +Cc: rth, egcs
On Sat, Feb 07, 1998 at 04:09:17PM -0500, Kaveh R. Ghazi wrote:
> 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?
Done.
r~
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is there a HOST_BITS_PER_POINTER macro?
@ 1998-02-07 13:09 Kaveh R. Ghazi
1998-02-07 13:29 ` Richard Henderson
0 siblings, 1 reply; 8+ messages in thread
From: Kaveh R. Ghazi @ 1998-02-07 13:09 UTC (permalink / raw)
To: rth; +Cc: egcs
> 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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is there a HOST_BITS_PER_POINTER macro?
1998-02-05 22:09 ` Richard Henderson
@ 1998-02-06 0:57 ` Jeffrey A Law
0 siblings, 0 replies; 8+ messages in thread
From: Jeffrey A Law @ 1998-02-06 0:57 UTC (permalink / raw)
To: Richard Henderson; +Cc: Kaveh R. Ghazi, egcs
In message < 19980205221028.48772@dot.cygnus.com >you write:
> On Thu, Feb 05, 1998 at 07:45:09PM -0500, Kaveh R. Ghazi wrote:
> > I get a warning from "-W -Wall" which complains about int format vs
> > pointer argument. Is there a way to define a macro in machmode.h
> > which can cast the pointer to the appropriately sized integer type?
>
> Ideally you would use "%p" everywhere, but to support bootstrapping,
> we should probably autoconf a test for that.
Agreed.
We autoconf test for it, then define/use HOST_PTR_PRINTF appropriately.
jeff
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is there a HOST_BITS_PER_POINTER macro?
1998-02-05 16:45 Kaveh R. Ghazi
1998-02-05 22:09 ` Richard Henderson
@ 1998-02-05 22:09 ` Joern Rennecke
1 sibling, 0 replies; 8+ messages in thread
From: Joern Rennecke @ 1998-02-05 22:09 UTC (permalink / raw)
To: Kaveh R. Ghazi; +Cc: egcs
> If I have the following in gcc's src code:
>
> char * foo;
> [...]
> printf(HOST_PTR_PRINTF, foo);
>
> I get a warning from "-W -Wall" which complains about int format vs
> pointer argument. Is there a way to define a macro in machmode.h
> which can cast the pointer to the appropriately sized integer type?
> I'd like to do the following
Even if you had something like that (e.g. ptrdiff_t on systems that
have it), that would be little help: You'd have to make sure that the
integer type matches the format specifier.
I think the most portable you can get without autoconf help is to
use long consistently, i.e. cast to long and use a long format specifier.
Of course that will still fail when pointers are wider than long...
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Is there a HOST_BITS_PER_POINTER macro?
1998-02-05 16:45 Kaveh R. Ghazi
@ 1998-02-05 22:09 ` Richard Henderson
1998-02-06 0:57 ` Jeffrey A Law
1998-02-05 22:09 ` Joern Rennecke
1 sibling, 1 reply; 8+ messages in thread
From: Richard Henderson @ 1998-02-05 22:09 UTC (permalink / raw)
To: Kaveh R. Ghazi; +Cc: egcs
On Thu, Feb 05, 1998 at 07:45:09PM -0500, Kaveh R. Ghazi wrote:
> I get a warning from "-W -Wall" which complains about int format vs
> pointer argument. Is there a way to define a macro in machmode.h
> which can cast the pointer to the appropriately sized integer type?
Ideally you would use "%p" everywhere, but to support bootstrapping,
we should probably autoconf a test for that.
r~
^ permalink raw reply [flat|nested] 8+ messages in thread
* Is there a HOST_BITS_PER_POINTER macro?
@ 1998-02-05 16:45 Kaveh R. Ghazi
1998-02-05 22:09 ` Richard Henderson
1998-02-05 22:09 ` Joern Rennecke
0 siblings, 2 replies; 8+ messages in thread
From: Kaveh R. Ghazi @ 1998-02-05 16:45 UTC (permalink / raw)
To: egcs
If I have the following in gcc's src code:
char * foo;
[...]
printf(HOST_PTR_PRINTF, foo);
I get a warning from "-W -Wall" which complains about int format vs
pointer argument. Is there a way to define a macro in machmode.h
which can cast the pointer to the appropriately sized integer type?
I'd like to do the following
printf(HOST_PTR_PRINTF, (HOST_PTR_PRINTF_CAST) foo);
I think I need something that can be evaluated by cpp, not cc1. So that
means I can't use sizeof. If I could find a HOST_BITS_PER_PTR macro, I
could handle this in machmode.h. But I can't find something like this
in the config files.
Thanks,
--Kaveh
--
Kaveh R. Ghazi Project Manager / Custom Development
ghazi@caip.rutgers.edu ICon CMT Corp.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~1998-02-10 3:34 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-02-06 8:48 Is there a HOST_BITS_PER_POINTER macro? Kaveh R. Ghazi
1998-02-10 3:34 ` Richard Henderson
-- strict thread matches above, loose matches on Subject: below --
1998-02-07 13:09 Kaveh R. Ghazi
1998-02-07 13:29 ` Richard Henderson
1998-02-05 16:45 Kaveh R. Ghazi
1998-02-05 22:09 ` Richard Henderson
1998-02-06 0:57 ` Jeffrey A Law
1998-02-05 22:09 ` Joern Rennecke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).