Don't use G_STRLOC



Unfortunately, with GCC 3.0 or greater, G_STRLOC is going to have
to be only FILE:LINE -- the behavior of __PRETTY_FUNCTION__ is
changing in 3.2 and even current versions spew lots of warnings
about concetenating use of __PRETTY_FUNCTION__.

(http://bugzilla.gnome.org/show_bug.cgi?id=69097 has some details)

We can conditionalize the use of __PRETTY_FUNCTION__ on GCC version,
but soon enough the situation will be:

 G_STRLOC will give FILE:LINE on non GCC systems
 G_STRLOC will give FILE:LINE on current GCC systems
 G_STRLOC will give FILE:LINE:FUNCTION on old GCC systems

In view of this, I'd suggest that people don't use G_STRLOC,
and change:

 g_warning (G_STRLOC "you can't do that!")

to:

 g_warning ("myfunc(): you can't do that!")

or:

 g_warning ("%s:%d:myfunc(): you can't do that!", __FILE__, __LINE__)

If you feel the file/line is important. 

Another option we have is to make G_STRLOC always FILE/LINE so you 
can do:

 g_warning (G_STRLOC "myfunc(): you can't do that!")

Without worrying about getting:

 foo.c:53:myfunc():myfunc(): you can't do that.

I'm not really sold that this has advantages above just avoiding
use of G_STRLOC(), however.

[ Similary, G_GNUC_PRETTY_NAME should be expected to shortly give
  "" on almost all compilers. ]

In 2.2, we should introduce G_FUNCTION_NAME that is __func__ on
C99 compilers, and __PRETTY_FUNCTION__ on older GCC. (Or perhaps
on all GCC if __PRETTY_FUNCTION__ gives nicer results that __func__.)

Regards,
                                        Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]