summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael McMaster <email@michaelmcmaster.name>2009-04-19 15:03:00 +0200
committerPeter Simons <simons@cryp.to>2009-04-19 15:03:00 +0200
commit2f6e6917dbf2d25e0198a36f0d0f25ffca7240d7 (patch)
tree9cd8301bcaeaec910ad8229b71bfbc86e2269ebb
parent7a3d510dbb742d0398da1557a9567168ec267c1a (diff)
downloadautoconf-archive-2f6e6917dbf2d25e0198a36f0d0f25ffca7240d7.tar.gz
AX_C99_INLINE: initial version
The macro determines whether the "inline" keyword of a C99 compiler is standards compliant or not.  I am using this macro support differences between gcc 4.2 (and earlier) and gcc 4.3 (and later) when using the "-std= c99" option.  It may also be useful for other compilers.  (For details of the differences between the compiler versions refer to http:// gcc.gnu.org/gcc-4.3/porting_to.html "Sematic change of extern inline") Example configure.ac: AC_INIT([foo], [0.1]) AM_INIT_AUTOMAKE AC_PROG_CC AC_PROG_CC_C99 if test "$ac_cv_prog_cc_c99" == "no"; then AC_MSG_ERROR([A C99 compiler is required.]) fi AX_C99_INLINE AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT Example source file foo.h: #ifdef HAVE_C99_INLINE inline int myFunction(int a) { return a + 1; } #else static inline int myFunction(int a) { return a + 1; } #endif Example source foo.c: extern inline int myFunction(int a);
-rw-r--r--AUTHORS1
-rw-r--r--ax_c99_inline.m465
2 files changed, 66 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
index 2b5be27..bcbcfaf 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -91,6 +91,7 @@ Autoconf Macro Contributors
Nick Markham
Nic Ferrier
Neil Ferguson
+ Michael McMaster
Matthieu Moy
Mats Kindahl of Sun Microsystems
Marten Svantesson
diff --git a/ax_c99_inline.m4 b/ax_c99_inline.m4
new file mode 100644
index 0000000..341b92f
--- /dev/null
+++ b/ax_c99_inline.m4
@@ -0,0 +1,65 @@
+# ===========================================================================
+# http://autoconf-archive.cryp.to/ax_c99_inline.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_C99_INLINE
+#
+# DESCRIPTION
+#
+# This macro defines HAVE_C99_INLINE if the C compiler supports "inline"
+# and "extern inline" correctly. An application may replace "inline" with
+# "static inline" as a workaround for older compilers.
+#
+# LAST MODIFICATION
+#
+# 2009-04-10
+#
+# COPYLEFT
+#
+# Copyright (c) 2009 Michael McMaster <email@michaelmcmaster.name>
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved.
+
+AC_DEFUN([AX_C99_INLINE], [
+ AC_MSG_CHECKING([whether the compiler supports C99 inline functions])
+ AC_REQUIRE([AC_PROG_CC_C99])
+
+ AC_LANG_PUSH([C])
+
+ dnl In a conforming C99 implementation a function marked "inline" will not
+ dnl be compiled into the translation unit if the compiler was not able to
+ dnl inline the function.
+ dnl GCC versions before 4.3 would output the inline functions into all
+ dnl translation units that could require the definition.
+ AC_LINK_IFELSE(
+ AC_LANG_SOURCE([
+ inline void* foo() { foo(); return &foo; }
+ int main() { return foo() != 0;}
+ ]),
+
+ dnl the invalid source compiled, so the inline keyword does not work
+ dnl correctly.
+ AC_MSG_RESULT([no]),
+
+ dnl Secondary test of valid source.
+ AC_LINK_IFELSE(
+ AC_LANG_SOURCE([
+ extern inline void* foo() { foo(); return &foo; }
+ int main() { return foo() != 0;}
+ ]),
+
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([HAVE_C99_INLINE], [1],
+ [Define to 1 if the "extern" keyword controls whether an inline function appears in a translation unit.]),
+
+ dnl Perhaps inline functions aren't supported at all ?
+ AC_MSG_RESULT([no])
+ )
+ )
+
+ AC_LANG_POP([C])
+ ]);