This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[RFC,PATCH] Builtin macros for sizes of standard types
- From: Andreas Krebbel <Andreas dot Krebbel at de dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 9 Jan 2007 17:40:53 +0100
- Subject: [RFC,PATCH] Builtin macros for sizes of standard types
Hi,
the attached patch introduces a new set of gcc builtin macros for
the sizes of c standard data types. I think those come in quite handy
when building preprocessor checks without special configure magic.
I would like to use these macros in libgcc unwind code in order to get rid
of the mode(word) type attribute. Don't panic I do not intend to add a
__SIZEOF_WORD__ macro ;)
I couldn't find a function converting a HOST_WIDE_INT into a string.
Do we have something like that?
Does anyone agree with me that this might be helpful and worth to be
integrated?
Bye,
-Andreas-
Index: gcc/c-cppbuiltin.c
===================================================================
*** gcc/c-cppbuiltin.c.orig 2006-11-03 13:51:34.000000000 +0100
--- gcc/c-cppbuiltin.c 2007-01-09 17:25:07.000000000 +0100
*************** builtin_define_stdint_macros (void)
*** 392,397 ****
--- 392,399 ----
void
c_cpp_builtins (cpp_reader *pfile)
{
+ char str[32];
+
/* -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)