From e2b97acafd3137d8cf3fc847a83e0946bd6203f2 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 27 Aug 2009 23:30:11 +0200 Subject: [PATCH] Avoid sizeof __func__ == 0 pitfall. --- ChangeLog | 6 ++++++ doc/func.texi | 3 +++ tests/test-func.c | 9 ++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index aa562e051..63e05d104 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2009-08-27 Bruno Haible + * tests/test-func.c (main): Don't verify sizeof __func__ on SunPRO C + compilers. + * doc/func.texi: Document the SunPRO C bug. + +2009-08-27 Bruno Haible + Fix link error on Solaris. * tests/test-parse-duration.c (xstrdup): Remove function. diff --git a/doc/func.texi b/doc/func.texi index 7a843c374..7225ca629 100644 --- a/doc/func.texi +++ b/doc/func.texi @@ -15,3 +15,6 @@ int main (void) printf ("%s: hello world\n", __func__); @} @end smallexample + +Note that @code{sizeof} cannot be applied to @code{__func__}: On SunPRO C +compiler, @code{sizeof __func__} evaluates to 0. diff --git a/tests/test-func.c b/tests/test-func.c index e55fcd5a9..8a3c465e7 100644 --- a/tests/test-func.c +++ b/tests/test-func.c @@ -1,5 +1,5 @@ /* Test whether __func__ is available - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2009 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 @@ -37,6 +37,13 @@ int main () { + ASSERT (strlen (__func__) > 0); + + /* On SunPRO C 5.9, sizeof __func__ evaluates to 0. The compiler warns: + "warning: null dimension: sizeof()". */ +#if !defined __SUNPRO_C ASSERT (strlen (__func__) + 1 == sizeof __func__); +#endif + return 0; } -- 2.11.0