]> granicus.if.org Git - nethack/commit
remove use of __FUNCTION__
authorPatR <rankin@nethack.org>
Sat, 6 Jun 2015 01:18:19 +0000 (18:18 -0700)
committerPatR <rankin@nethack.org>
Sat, 6 Jun 2015 01:18:19 +0000 (18:18 -0700)
commitc890269947dd808571b2e0a083fc484852f69759
treebac729b679de8f78809922211656a2e45beea122
parent04783f1c8a9a95f6817eadf32579c757f7f43d7b
remove use of __FUNCTION__

The special level loader has been using __FUNCTION__ in error messages
for a few months now, but that is a gcc extension (evidently picked up
by other compilers since only Borland had an issue so far).  The
standard way to do the same thing is with __func__, but that's C99 so
we should avoid it.  (__FUNCTION__ came earlier; gcc supports both.)

This switches to convential C code to achieve the same effect, using
the name 'nhFunc' rather than __FUNCTION__:
  void foo()
  {
    static const char nhFunc[] = "foo";
    ... code that might report problem in nhFunc ...
    return;
  }
This has only been added to the functions which actually reference it,
not a blanket intrusion into every routine.  In special level loader's
case, the reference is hidden in the opvar_free() macro which is used
quite a lot.

At first I used a macro:
  void foo()
  {
  #define nhFunc "foo"
    ... code that might report problem in nhFunc ...
    return;
  #undef nhFunc
  }
but using an actual variable avoids duplicate copies of the function
name string when used more than once inside a given function, and it
can't accidentally carry over into the next function due to missing or
misspelled #undef.

If we someday switch alloc() to give more specific information than
__FILE__, the macro variation would be better since the function name
won't be used most of the time (ie, when MONITOR_HEAP isn't defined).
src/sp_lev.c