[illumos-Developer] __FUNCTION__ in illumos

Alan Coopersmith alan.coopersmith at oracle.com
Thu Dec 16 13:07:18 PST 2010


Albert Lee wrote:
> This would work assuming every compilation unit with __FUNCTION__
> includes a system header, but I'm not sure about the impact outside of
> ON where we have no control over which compilers are used. As it's not
> a true preprocessor macro in the two common compilers that support it,
> we can't test for feature presence (although we could restrict the
> macro definition to __SUNPRO_C of course).

The most complete definition I've seen (and contributed the Studio checks
to), which is far more cross-platform than illumos needs, is from Mesa:

#ifndef __FUNCTION__
# if defined(__VMS)
#  define __FUNCTION__ "VMS$NL:"
# elif !defined(__GNUC__) && !defined(__xlC__) &&       \
      (!defined(_MSC_VER) || _MSC_VER < 1300)
#  if (__STDC_VERSION__ >= 199901L) /* C99 */ || \
    (defined(__SUNPRO_C) && defined(__C99FEATURES__))
#   define __FUNCTION__ __func__
#  else
#   define __FUNCTION__ "<unknown>"
#  endif
# endif
#endif

For illumos, you could probably simplify to (quickly edited in
e-mail, not even compile tested):

#if !defined(__FUNCTION__) && !defined(__GNUC__)
# if (__STDC_VERSION__ >= 199901L) /* C99 */ || \
    (defined(__SUNPRO_C) && defined(__C99FEATURES__))
#  define __FUNCTION__ __func__
# else
#  define __FUNCTION__ "<unknown>"
# endif
#endif

which should keep it from failing in any code built with
-Xc -xc99=%none or similar flags to disable C99isms.

-- 
	-Alan Coopersmith-        alan.coopersmith at oracle.com
	 Oracle Solaris Platform Engineering: X Window System




More information about the Developer mailing list