This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Use "%I64d" on Windows


The Windows C library uses "%I64d", not "%lld", to print arguments of
type "long long".

GCC will complain that this is an unknown printf-format on Windows;
the fix will be to use the machinery added for Solaris 10 to handle
the various Windows-specific formats.

Tested by building a cross-compiler to Windows for mips64-none-elf,
and looking at the generated .i files, applied on the mainline.
Although I did not heavily test the compiler built in this way, I did
test a very similar compiler built for a customer using this same
patch.  

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2004-11-23  Mark Mitchell  <mark@codesourcery.com>

	* hwint.h (HOST_LONG_LONG_FORMAT): New macro.  Use it throughout.
	* config/i386/xm-mingw32.h (HOST_LONG_LONG_FORMAT): Define.
	* doc/hostconfig.texi (HOST_LONG_LONG_FORMAT): Document.

Index: hwint.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/hwint.h,v
retrieving revision 1.19
diff -c -5 -p -r1.19 hwint.h
*** hwint.h	15 Oct 2004 14:47:08 -0000	1.19
--- hwint.h	24 Nov 2004 04:25:08 -0000
***************
*** 13,22 ****
--- 13,28 ----
  #define HOST_BITS_PER_CHAR  CHAR_BIT
  #define HOST_BITS_PER_SHORT (CHAR_BIT * SIZEOF_SHORT)
  #define HOST_BITS_PER_INT   (CHAR_BIT * SIZEOF_INT)
  #define HOST_BITS_PER_LONG  (CHAR_BIT * SIZEOF_LONG)
  
+ /* The string that should be inserted into a printf style format to
+    indicate a "long long" operand.  */
+ #ifndef HOST_LONG_LONG_FORMAT 
+ #define HOST_LONG_LONG_FORMAT "ll"
+ #endif
+ 
  /* If HAVE_LONG_LONG and SIZEOF_LONG_LONG aren't defined, but
     GCC_VERSION >= 3000, assume this is the second or later stage of a
     bootstrap, we do have long long, and it's 64 bits.  (This is
     required by C99; we do have some ports that violate that assumption
     but they're all cross-compile-only.)  Just in case, force a
*************** extern char sizeof_long_long_must_be_8[s
*** 75,85 ****
  # endif
  #else
  # define HOST_WIDE_INT_PRINT "ll"
  # define HOST_WIDE_INT_PRINT_C "LL"
    /* We can assume that 'long long' is at least 64 bits.  */
! # define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%llx%016llx"
  #endif /* HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG */
  
  #define HOST_WIDE_INT_PRINT_DEC "%" HOST_WIDE_INT_PRINT "d"
  #define HOST_WIDE_INT_PRINT_DEC_C HOST_WIDE_INT_PRINT_DEC HOST_WIDE_INT_PRINT_C
  #define HOST_WIDE_INT_PRINT_UNSIGNED "%" HOST_WIDE_INT_PRINT "u"
--- 81,92 ----
  # endif
  #else
  # define HOST_WIDE_INT_PRINT "ll"
  # define HOST_WIDE_INT_PRINT_C "LL"
    /* We can assume that 'long long' is at least 64 bits.  */
! # define HOST_WIDE_INT_PRINT_DOUBLE_HEX \
!     "0x%" HOST_LONG_LONG_FORMAT "x%016" HOST_LONG_LONG_FORMAT "x"
  #endif /* HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG */
  
  #define HOST_WIDE_INT_PRINT_DEC "%" HOST_WIDE_INT_PRINT "d"
  #define HOST_WIDE_INT_PRINT_DEC_C HOST_WIDE_INT_PRINT_DEC HOST_WIDE_INT_PRINT_C
  #define HOST_WIDE_INT_PRINT_UNSIGNED "%" HOST_WIDE_INT_PRINT "u"
*************** extern char sizeof_long_long_must_be_8[s
*** 107,121 ****
  #   define HOST_WIDEST_INT		      __int64
  #  else
      #error "This line should be impossible to reach"
  #  endif
  # endif
! # define HOST_WIDEST_INT_PRINT_DEC	      "%lld"
! # define HOST_WIDEST_INT_PRINT_DEC_C	      "%lldLL"
! # define HOST_WIDEST_INT_PRINT_UNSIGNED	      "%llu"
! # define HOST_WIDEST_INT_PRINT_HEX	      "0x%llx"
! # define HOST_WIDEST_INT_PRINT_DOUBLE_HEX     "0x%llx%016llx"
  #endif
  
  /* Define HOST_WIDEST_FAST_INT to the widest integer type supported
     efficiently in hardware.  (That is, the widest integer type that fits
     in a hardware register.)  Normally this is "long" but on some hosts it
--- 114,129 ----
  #   define HOST_WIDEST_INT		      __int64
  #  else
      #error "This line should be impossible to reach"
  #  endif
  # endif
! # define HOST_WIDEST_INT_PRINT_DEC	      "%" HOST_LONG_LONG_FORMAT "d"
! # define HOST_WIDEST_INT_PRINT_DEC_C	      "%" HOST_LONG_LONG_FORMAT "dLL"
! # define HOST_WIDEST_INT_PRINT_UNSIGNED	      "%" HOST_LONG_LONG_FORMAT "u"
! # define HOST_WIDEST_INT_PRINT_HEX	      "0x%" HOST_LONG_LONG_FORMAT "x"
! # define HOST_WIDEST_INT_PRINT_DOUBLE_HEX     \
!     "0x%" HOST_LONG_LONG_FORMAT "x%016" HOST_LONG_LONG_FORMAT "x"
  #endif
  
  /* Define HOST_WIDEST_FAST_INT to the widest integer type supported
     efficiently in hardware.  (That is, the widest integer type that fits
     in a hardware register.)  Normally this is "long" but on some hosts it
Index: config/i386/xm-mingw32.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/xm-mingw32.h,v
retrieving revision 1.21
diff -c -5 -p -r1.21 xm-mingw32.h
*** config/i386/xm-mingw32.h	20 Aug 2004 11:14:11 -0000	1.21
--- config/i386/xm-mingw32.h	24 Nov 2004 04:25:08 -0000
*************** Software Foundation, 59 Temple Place - S
*** 28,32 ****
--- 28,36 ----
  /* This is the name of the null device on windows.  */
  #define HOST_BIT_BUCKET "nul"
  
  /*  The st_ino field of struct stat is always 0.  */
  #define HOST_LACKS_INODE_NUMBERS
+ 
+ /* MSVCRT does not support the "ll" format specifier for printing
+    "long long" values.  Instead, we use "I64".  */
+ #define HOST_LONG_LONG_FORMAT "I64"
Index: doc/hostconfig.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/hostconfig.texi,v
retrieving revision 1.14
diff -c -5 -p -r1.14 hostconfig.texi
*** doc/hostconfig.texi	5 Nov 2004 01:36:56 -0000	1.14
--- doc/hostconfig.texi	24 Nov 2004 04:30:18 -0000
*************** initialization when a compilation driver
*** 210,219 ****
--- 210,224 ----
  
  @item SMALL_ARG_MAX
  Define this macro if the host system has a small limit on the total
  size of an argument vector.  This causes the driver to take more care
  not to pass unnecessary arguments to subprocesses.
+ 
+ @item HOST_LONG_LONG_FORMAT
+ If defined, the string used to indicate an argument of type @code{long
+ long} to functions like @code{printf}.  The default value is
+ @code{"ll"}. 
  @end ftable
  
  In addition, if @command{configure} generates an incorrect definition of
  any of the macros in @file{auto-host.h}, you can override that
  definition in a host configuration header.  If you need to do this,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]