[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: AC_CHECK_SIZEOF
From: |
Paul Eggert |
Subject: |
Re: AC_CHECK_SIZEOF |
Date: |
Wed, 11 Apr 2007 17:12:21 -0700 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux) |
Ralf Wildenhues <address@hidden> writes:
> I don't see a simple way for Autoconf to deal with function types
> short of writing a parser for C function declarations, for the
> AC_CHECK_{TYPE,TYPES,SIZEOF,ALIGNOF} macros.
I can, for C (except for AC_CHECK_ALIGNOF). I can't see how to do it
for C++, but perhaps a C++ wizard can figure that out later. I
installed this:
2007-04-11 Paul Eggert <address@hidden>
* doc/autoconf.texi (Generic Types): Document the restrictions
on types imposed by AC_CHECK_TYPE, AC_CHECK_TYPES.
(Generic Compiler Characteristics): AC_CHECK_SIZEOF now works
with objects too. Document the restrictions on its use.
Document the restrictions on AC_CHECK_ALIGNOF's type argument.
* lib/autoconf/types.m4 (_AC_CHECK_TYPE_NEW):
For C, just try sizeof (TYPE) and sizeof ((TYPE)); if the former
works but the latter doesn't, then it's a valid type.
This lets people use function types and so forth.
For C++ there doesn't seem to be a simple solution, so leave it alone.
(AC_CHECK_SIZEOF): Allow argument to be a variable.
(AC_CHECK_SIZEOF, AC_CHECK_ALIGNOF): Don't bother to invoke
AC_CHECK_TYPE; that wasn't documented or necessary.
Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.1144
diff -u -p -r1.1144 autoconf.texi
--- doc/autoconf.texi 11 Apr 2007 17:15:37 -0000 1.1144
+++ doc/autoconf.texi 12 Apr 2007 00:12:02 -0000
@@ -6119,13 +6119,22 @@ test macros.
@acindex{CHECK_TYPE}
Check whether @var{type} is defined. It may be a compiler builtin type
or defined by the @var{includes} (@pxref{Default Includes}).
+
+In C, @var{type} must be a type-id, so that the expression @samp{sizeof
+(@var{type})} is valid (but @samp{sizeof ((@var{type}))} is not). The
+rules in C++ are currently more complicated and restrictive: @var{type}
+must be a string of tokens such that @samp{typedef @var{type} foo;} is a
+valid type definition. However, the C++ approach has problems (for
+example, it mishandles function types) and may change in future versions
+of Autoconf.
@end defmac
@defmac AC_CHECK_TYPES (@var{types}, @ovar{action-if-found},
@ovar{action-if-not-found}, @dvar{includes, default-includes})
@acindex{CHECK_TYPES}
For each @var{type} of the @var{types} that is defined, define
address@hidden@var{type}} (in all capitals). If no @var{includes} are
address@hidden@var{type}} (in all capitals). Each @var{type} must follow
+the rules of @code{AC_CHECK_TYPE}. If no @var{includes} are
specified, the default includes are used (@pxref{Default Includes}). If
@var{action-if-found} is given, it is additional shell code to execute
when one of the types is found. If @var{action-if-not-found} is given,
@@ -6208,11 +6217,13 @@ Autoconf works around this problem by ca
@node Generic Compiler Characteristics
@subsection Generic Compiler Characteristics
address@hidden AC_CHECK_SIZEOF (@var{type}, @ovar{unused}, @dvar{includes,
default-includes})
address@hidden AC_CHECK_SIZEOF (@var{type-or-expr}, @ovar{unused},
@dvar{includes, default-includes})
@acindex{CHECK_SIZEOF}
-Define @address@hidden (@pxref{Standard Symbols}) to be the
-size in bytes of @var{type}. If @samp{type} is unknown, it gets a size
-of 0. If no @var{includes} are specified, the default includes are used
+Define @address@hidden (@pxref{Standard Symbols}) to be
+the size in bytes of @var{type-or-expr}, which may be either a type or
+an expression returning a value that has a size. If the expression
address@hidden (@var{type-or-expr})} is invalid, the result is 0. If no
address@hidden are specified, the default includes are used
(@pxref{Default Includes}).
This macro now works even when cross-compiling. The @var{unused}
@@ -6231,8 +6242,9 @@ defines @code{SIZEOF_INT_P} to be 8 on D
@defmac AC_CHECK_ALIGNOF (@var{type}, @dvar{includes, default-includes})
@acindex{CHECK_ALIGNOF}
Define @address@hidden (@pxref{Standard Symbols}) to be the
-alignment in bytes of @var{type}. If @samp{type} is unknown, it gets a size
-of 0. If no @var{includes} are specified, the default includes are used
+alignment in bytes of @var{type}. @address@hidden x;} must be valid as
+a structure member declaration. If @samp{type} is unknown, the result
+is 0. If no @var{includes} are specified, the default includes are used
(@pxref{Default Includes}).
@end defmac
Index: lib/autoconf/types.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/types.m4,v
retrieving revision 1.50
diff -u -p -r1.50 types.m4
--- lib/autoconf/types.m4 28 Nov 2006 00:26:45 -0000 1.50
+++ lib/autoconf/types.m4 12 Apr 2007 00:12:02 -0000
@@ -130,8 +130,11 @@
# But this succeeds if TYPE is a variable: you get the size of the
# variable's type!!!
#
-# This time you tell yourself the last two options *together* will make
-# it. And indeed this is the solution invented by Alexandre Oliva.
+# So, to filter out the last possibility, you try this too:
+#
+# sizeof ((TYPE));
+#
+# This fails if TYPE is a type, but succeeds if TYPE is actually a variable.
#
# Also note that we use
#
@@ -140,24 +143,37 @@
# to `read' sizeof (to avoid warnings), while not depending on its type
# (not necessarily size_t etc.). Equally, instead of defining an unused
# variable, we just use a cast to avoid warnings from the compiler.
-# Suggested by Paul Eggert.
#
# Now, the next issue is that C++ disallows defining types inside casts
# and inside `sizeof()', but we would like to allow unnamed structs, for
-# use inside AC_CHECK_SIZEOF, for example. So we create a typedef of the
-# new type. Note that this does not obviate the need for the other
-# constructs in general.
+# use inside AC_CHECK_SIZEOF, for example. So for C++ we create a typedef
+# of the new type. Note that this breaks for some types, e.g., function
+# types, but we don't know C++ well enough to fix this.
m4_define([_AC_CHECK_TYPE_NEW],
[AS_VAR_PUSHDEF([ac_Type], [ac_cv_type_$1])dnl
AC_CACHE_CHECK([for $1], [ac_Type],
-[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])
-typedef $1 ac__type_new_;],
-[if ((ac__type_new_ *) 0)
+[AS_VAR_SET([ac_Type], [no])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])
+#ifdef __cplusplus
+typedef $1 ac__type_new_;
+#endif
+],
+[#ifdef __cplusplus
+if ((ac__type_new_ *) 0)
return 0;
if (sizeof (ac__type_new_))
- return 0;])],
- [AS_VAR_SET([ac_Type], [yes])],
- [AS_VAR_SET([ac_Type], [no])])])
+ return 0;
+#else
+if (sizeof ($1))
+ return 0;
+#endif
+])],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])],
+ [if (sizeof (($1)))
+ return 0;])],
+ [],
+ [AS_VAR_SET([ac_Type], [yes])])])])
AS_IF([test AS_VAR_GET([ac_Type]) = yes], [$2], [$3])[]dnl
AS_VAR_POPDEF([ac_Type])dnl
])# _AC_CHECK_TYPE_NEW
@@ -703,15 +719,13 @@ AC_DEFINE_UNQUOTED(RETSIGTYPE, $ac_cv_ty
AC_DEFUN([AC_CHECK_SIZEOF],
[AS_LITERAL_IF([$1], [],
[AC_FATAL([$0: requires literal arguments])])dnl
-AC_CHECK_TYPE([$1], [], [], [$3])
# The cast to long int works around a bug in the HP C Compiler
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
# This bug is HP SR number 8606223364.
_AC_CACHE_CHECK_INT([size of $1], [AS_TR_SH([ac_cv_sizeof_$1])],
- [(long int) (sizeof (ac__type_sizeof_))],
- [AC_INCLUDES_DEFAULT([$3])
- typedef $1 ac__type_sizeof_;],
+ [(long int) (sizeof ($1))],
+ [AC_INCLUDES_DEFAULT([$3])],
[if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
AC_MSG_FAILURE([cannot compute sizeof ($1)], 77)
else
@@ -728,7 +742,6 @@ AC_DEFINE_UNQUOTED(AS_TR_CPP(sizeof_$1),
AC_DEFUN([AC_CHECK_ALIGNOF],
[AS_LITERAL_IF([$1], [],
[AC_FATAL([$0: requires literal arguments])])dnl
-AC_CHECK_TYPE([$1], [], [], [$2])
# The cast to long int works around a bug in the HP C Compiler,
# see AC_CHECK_SIZEOF for more information.
_AC_CACHE_CHECK_INT([alignment of $1], [AS_TR_SH([ac_cv_alignof_$1])],
- Re: AC_CHECK_SIZEOF,
Paul Eggert <=