[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: __func__
From: |
Simon Josefsson |
Subject: |
Re: __func__ |
Date: |
Mon, 03 Mar 2008 17:05:27 +0100 |
User-agent: |
Gnus/5.110007 (No Gnus v0.7) Emacs/22.1 (gnu/linux) |
Bruno Haible <address@hidden> writes:
>> I was unsure where to document this, it isn't either a function or
>> header file, strictly speaking.
>
> I would put its documentation in chapter "Particular modules".
Thanks.
>> AH_VERBATIM(__FUNC__, [
>> #if __STDC_VERSION__ < 199901L
>
> Tests of __STDC_VERSION__ are often wrong, in either direction. A autoconf
> test is more likely to be right everywhere.
>
> Also, how about a unit test? It can be as simple as
Updated patch below.
Micah Cowan <address@hidden> writes:
> Bruno Haible wrote:
>> Simon Josefsson wrote:
>>> # define __func__ "<unknown>"
>>
>> Some packages use
>> #define __func__ __FILE__
>> in this case. Not perfect, but still more informative than "<unknown>".
>
> But, wouldn't one normally include __FILE__ in diagnostic output, anyway?
>
> #define whine(msg) ((void)fprintf(stderr, "%s(%s:%u): %s", __FILE__,
> __func__, __LINE__, (msg)))
>
> (sorry about line-breakage above.)
>
> If they don't do things like that, then yeah, __FILE__ is better than
> nothing. If they _do_, though, then it seems like
> "file.c(<unknown>:1971): blah" is less confusing than
> "file.c(file.c:1971): blah".
>
> Probably better to let the developers use that sort of logic, when they
> know how they're using it, than to provide that as the general fallback?
I think I agree with Micah here, but I don't care strongly. If someone
wants to propose a patch on top off this patch to change it, that would
be fine.
Ok to push?
/Simon
>From f557c4c328f78cc5e3c7ffdfe45f263d13675753 Mon Sep 17 00:00:00 2001
From: Simon Josefsson <address@hidden>
Date: Mon, 3 Mar 2008 17:03:50 +0100
Subject: [PATCH] Add module __func__ to provide C99 __func__ variable.
---
doc/gnulib.texi | 14 ++++++++++++++
m4/__func__.m4 | 17 +++++++++++++++++
modules/__func__ | 20 ++++++++++++++++++++
modules/__func__-tests | 8 ++++++++
tests/test-__func__.c | 41 +++++++++++++++++++++++++++++++++++++++++
5 files changed, 100 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..d4a54be 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 function 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..9888204
--- /dev/null
+++ b/m4/__func__.m4
@@ -0,0 +1,17 @@
+# __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_CHECK_DECLS([__func__])
+ AH_VERBATIM(__FUNC__, [
+#if !HAVE_DECL___FUNC__
+# define __func__ "<unknown function>"
+#endif
+ ])
+])
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 <=
- Re: __func__, Bruno Haible, 2008/03/03
- Re: __func__, Simon Josefsson, 2008/03/04
- 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