[Gc] Patch for adjusting printf actual param types
urkedal at nbi.dk
Sun Oct 26 04:34:26 PST 2008
On 2008-10-26, Ivan Maidanski wrote:
> Petter Urkedal <urkedal at nbi.dk> wrote:
> > On 2008-10-25, Ivan Maidanski wrote:
> > > This patch adjusts the types of actual parameters for GC_..._printf() according to its format specifiers.
> > Not to disagree with your patch, but how about imitating the C99
> > standard and add the following definitions to gc.h (next to the GC_word
> > typedef)?
> > #define GC_PRIdWORD "ld"
> > #define GC_PRIiWORD "li"
> > #define GC_PRIoWORD "lo"
> > #define GC_PRIuWORD "ld"
> > #define GC_PRIxWORD "lx"
> > #define GC_PRIXWORD "lX"
> > One of the print statements below would then look like
> > GC_printf("Free list %lu (total size %"GC_PRIuWORD");\n",
> > i, GC_free_bytes[i]);
> This is technically possible... But some tips:
> - this really only matters for LLP64 targets (like Win64 where
Interesting. And I though the possibility that "(long)word" would
truncate "word" was too hypothetical to mention.
> - printing in GC servers really the debugging and profiling purposes
> only (if someone wants to print, eg., number of free bytes left then
> he should use GC_get_free_space() call and print it manually);
> - hex printing of GC_word value could be done thru "%p" modifier
> (AFAIK, it's portable);
Yes, I think "%p" is in C89, at least, but it's not guaranteed to print
a plain hexadecimal number. glibc adds a "0x" in front, which may or
may not be desirable. Using "%p" we still need to cast the argument to
a pointer, which could be narrower than GC_word.
> - there should exist a volunteer to define these macros (across major
> compilers) and to use them consistently across the whole GC.
Looking at the source code, there are only two cases. Most platforms
use "unsigned long" which has a portable format specifier. The only
exception is _WIN64. I don't know if the library which define ULONG_PTR
and LONG_PTR also defined the corresponding print specifiers.
Introducing the print specifiers for GC_word, does not mean they have be
be consistently used across the whole GC. They give you an option for
new code and patches.
> > BTW, i is already long above, no cast needed.
> "i" var is unsigned (to prevent compiler warning since N_HBLK_FLS is
> unsigned) in my current snapshot version of GC (not CVS) - Hans still
> has a backlog of my suggested patches (neither committed nor
You're right. Then I suggest changing the print specifier to "%u"
rather than casting the argument to long.
More information about the Gc