[RFC,PATCH] Builtin macros for sizes of standard types

Andreas Krebbel Andreas.Krebbel@de.ibm.com
Wed Jan 10 17:38:00 GMT 2007


Hi,

I've added documentation for the new macros and bootstrapped the
patch on i686, s390 and s390x.  No testsuite regressions.

I've checked that the macros are defined properly and that the 
documentation builds fine.

OK for mainline?

Bye,

-Andreas-


2007-01-10  Andreas Krebbel  <krebbel1@de.ibm.com>

	* c-cppbuiltin.c (c_cpp_builtins): New builtin macros:
	__SIZEOF_INT__, __SIZEOF_LONG__, __SIZEOF_LONG_LONG__, 
	__SIZEOF_SHORT__ and __SIZEOF_VOID_P__.
	* doc/cpp.texi: Documentation for the new builtin macros
	added.


Index: gcc/c-cppbuiltin.c
===================================================================
*** gcc/c-cppbuiltin.c.orig	2006-11-03 13:51:34.000000000 +0100
--- gcc/c-cppbuiltin.c	2007-01-10 10:47:09.000000000 +0100
*************** builtin_define_stdint_macros (void)
*** 392,397 ****
--- 392,399 ----
  void
  c_cpp_builtins (cpp_reader *pfile)
  {
+   char str[22];
+ 
    /* -undef turns off target-specific built-ins.  */
    if (flag_undef)
      return;
*************** c_cpp_builtins (cpp_reader *pfile)
*** 549,554 ****
--- 551,571 ----
    if (flag_openmp)
      cpp_define (pfile, "_OPENMP=200505");
  
+   sprintf (str, HOST_WIDE_INT_PRINT_DEC,
+ 	   TREE_INT_CST_LOW (TYPE_SIZE_UNIT (long_integer_type_node)));
+   builtin_define_with_value ("__SIZEOF_LONG__", str, 0);
+   sprintf (str, HOST_WIDE_INT_PRINT_DEC,
+ 	   TREE_INT_CST_LOW (TYPE_SIZE_UNIT (long_long_integer_type_node)));
+   builtin_define_with_value ("__SIZEOF_LONG_LONG__", str, 0);
+   sprintf (str, HOST_WIDE_INT_PRINT_DEC,
+ 	   TREE_INT_CST_LOW (TYPE_SIZE_UNIT (integer_type_node)));
+   builtin_define_with_value ("__SIZEOF_INT__", str, 0);
+   sprintf (str, HOST_WIDE_INT_PRINT_DEC,
+ 	   TREE_INT_CST_LOW (TYPE_SIZE_UNIT (short_integer_type_node)));
+   builtin_define_with_value ("__SIZEOF_SHORT__", str, 0);
+   sprintf (str, "%u", POINTER_SIZE / BITS_PER_UNIT);
+   builtin_define_with_value ("__SIZEOF_VOID_P__", str, 0);
+ 
    /* A straightforward target hook doesn't work, because of problems
       linking that hook's body when part of non-C front ends.  */
  # define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
Index: gcc/doc/cpp.texi
===================================================================
*** gcc/doc/cpp.texi.orig	2006-11-03 13:50:53.000000000 +0100
--- gcc/doc/cpp.texi	2007-01-10 10:44:18.000000000 +0100
*************** respectively.  They exist to make the st
*** 2079,2084 ****
--- 2079,2092 ----
  work correctly.  You should not use these macros directly; instead, include
  the appropriate headers.
  
+ @item __SIZEOF_INT__
+ @itemx __SIZEOF_LONG__
+ @itemx __SIZEOF_LONG_LONG__
+ @itemx __SIZEOF_SHORT__
+ @itemx __SIZEOF_VOID_P__
+ Defined to the number of bytes of the c standard data types: @code{int},
+ @code{long}, @code{long long}, @code{short} and @code{void*}.
+ 
  @item __DEPRECATED
  This macro is defined, with value 1, when compiling a C++ source file
  with warnings about deprecated constructs enabled.  These warnings are



More information about the Gcc-patches mailing list