[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: __func__
From: |
Simon Josefsson |
Subject: |
Re: __func__ |
Date: |
Tue, 04 Mar 2008 15:39:21 +0100 |
User-agent: |
Gnus/5.110007 (No Gnus v0.7) Emacs/22.1 (gnu/linux) |
Bruno Haible <address@hidden> writes:
> Simon Josefsson wrote:
>> Ok to push?
>
> 3 nits:
>
>> +A small function is:
>> +
>> address@hidden
>> +#include <config.h>
>> +...
>> +printf ("%s: something happened\n", __func__);
>> address@hidden smallexample
>
> I don't see a function here. Did you mean "A small example is:" ?
Yes, thanks.
>> + AH_VERBATIM(__FUNC__, [
>> +#if !HAVE_DECL___FUNC__
>> +# define __func__ "<unknown function>"
>> +#endif
>> + ])
>
> This relies on the AH_VERBATIM argument to be inserted in config.h.in after
> the conditional HAVE_DECL___FUNC__ definition. But this is not guaranteed:
> AH_VERBATIMs are sorted according to the key, i.e. on "__FUNC__". But the
> other sort key (from AC_CHECK_DECLS) is not specified, nor is the locale.
>
> Isn't this simpler?
>
> AC_CHECK_DECLS([__func__])
> if test "$ac_cv_have_decl___func__" != yes; then
> AC_DEFINE([__func__], ["<unknown function>"],
> [Define as a replacement for the ISO C99 __func__ variable.])
> fi
>
>> + AC_CHECK_DECLS([__func__])
>
> Is this right?? AC_CHECK_DECLS checks for a declaration as a function. What
> you want is to know whether it's declared as a variable(!), when used inside
> a function(!).
>
> There is a macro gt_CHECK_VAR_DECL in gnulib, but it assumes the variable
> is also declared outside of functions.
>
> So I think this needs a hand-written AC_TRY_COMPILE invocation here.
Hm. As far as I can tell, AC_CHECK_DECLS is not restricted to
functions, the autoconf manual says "If SYMBOL (a function or a
variable) is not declared ...".
However, what do you think about this?
/Simon
>From 232f8a7255f8addd9724156d7d245b51a7feb72e Mon Sep 17 00:00:00 2001
From: Simon Josefsson <address@hidden>
Date: Tue, 4 Mar 2008 15:37:59 +0100
Subject: [PATCH] Add module __func__ to provide C99 __func__ variable.
---
doc/gnulib.texi | 14 ++++++++++++++
m4/__func__.m4 | 20 ++++++++++++++++++++
modules/__func__ | 20 ++++++++++++++++++++
modules/__func__-tests | 8 ++++++++
tests/test-__func__.c | 41 +++++++++++++++++++++++++++++++++++++++++
5 files changed, 103 insertions(+), 0 deletions(-)
create mode 100644 m4/__func__.m4
create mode 100644 modules/__func__
create mode 100644 modules/__func__-tests
create mode 100644 tests/test-__func__.c
diff --git a/doc/gnulib.texi b/doc/gnulib.texi
index 270bcb7..31f51df 100644
--- a/doc/gnulib.texi
+++ b/doc/gnulib.texi
@@ -5746,6 +5746,7 @@ This list of functions is sorted according to the header
that declares them.
* gcd::
* Regular expressions::
* Supporting Relocation::
+* __func__::
@end menu
@node alloca
@@ -5825,6 +5826,19 @@ generated automatically.
@include regexprops-generic.texi
address@hidden __func__
address@hidden __func__
+
+The @code{__func__} module makes sure that you can use the
address@hidden variable as defined by C99 in your code.
+
+A small example is:
+
address@hidden
+#include <config.h>
+...
+printf ("%s: something happened\n", __func__);
address@hidden smallexample
@node GNU Free Documentation License
@appendix GNU Free Documentation License
diff --git a/m4/__func__.m4 b/m4/__func__.m4
new file mode 100644
index 0000000..ee39f42
--- /dev/null
+++ b/m4/__func__.m4
@@ -0,0 +1,20 @@
+# __func__.m4 serial 1
+dnl Copyright (C) 2008 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# Written by Simon Josefsson
+
+AC_DEFUN([gl___FUNC__],
+[
+ AC_CACHE_CHECK([whether __func__ is available], [gl_cv_var___func__],
+ AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([[]], [[const char *str = __func__;]])],
+ [gl_cv_var___func__=yes],
+ [gl_cv_var___func__=no]))
+ if test "$gl_cv_var___func__" != yes; then
+ AC_DEFINE([__func__], ["<unknown function>"],
+ [Define as a replacement for the ISO C99 __func__ variable.])
+ fi
+])
diff --git a/modules/__func__ b/modules/__func__
new file mode 100644
index 0000000..79eae75
--- /dev/null
+++ b/modules/__func__
@@ -0,0 +1,20 @@
+Description:
+Make sure __func__ is usable even on non-C99 platforms.
+
+Files:
+m4/__func__.m4
+
+Depends-on:
+
+configure.ac:
+gl___FUNC__
+
+Makefile.am:
+
+Include:
+
+License:
+LGPL
+
+Maintainer:
+Simon Josefsson
diff --git a/modules/__func__-tests b/modules/__func__-tests
new file mode 100644
index 0000000..4d821a3
--- /dev/null
+++ b/modules/__func__-tests
@@ -0,0 +1,8 @@
+Files:
+tests/test-__func__.c
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-__func__
+check_PROGRAMS += test-__func__
diff --git a/tests/test-__func__.c b/tests/test-__func__.c
new file mode 100644
index 0000000..afa6159
--- /dev/null
+++ b/tests/test-__func__.c
@@ -0,0 +1,41 @@
+/* Test whether __func__ is available
+ Copyright (C) 2008 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <address@hidden>, 2008. */
+
+#include <config.h>
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define ASSERT(expr) \
+ do \
+ { \
+ if (!(expr)) \
+ { \
+ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+ abort (); \
+ } \
+ } \
+ while (0)
+
+int
+main ()
+{
+ ASSERT (strlen (__func__) + 1 == sizeof (__func__));
+ return 0;
+}
--
1.5.4.1
- Re: __func__, Simon Josefsson, 2008/03/03
- Re: __func__, Bruno Haible, 2008/03/03
- Re: __func__,
Simon Josefsson <=
- Re: __func__, Bruno Haible, 2008/03/04
- Re: __func__, Simon Josefsson, 2008/03/06
- Re: AC_COMPILE_IFELSE, Bruno Haible, 2008/03/06
- Re: AC_COMPILE_IFELSE, Ralf Wildenhues, 2008/03/06
- Re: AC_COMPILE_IFELSE, Bruno Haible, 2008/03/06
- Re: AC_COMPILE_IFELSE, Eric Blake, 2008/03/06
- Re: __func__, Eric Blake, 2008/03/04
- Re: __func__, Simon Josefsson, 2008/03/06
- Re: __func__, Jim Meyering, 2008/03/06
- Re: __func__, Simon Josefsson, 2008/03/06