[linux-elitists] Stupid C tricks

Jason Spence jspence@lightconsulting.com
Sat Aug 28 16:42:06 PDT 2004

On Sun, Aug 29, 2004 at 09:14:40AM +1000, Martin Pool wrote: 
> You can define things so that you do without the function name on MS
> C.  This may be enough if gcc is your main platform:
>   http://sourcefrog.net/archzoom/mbp@sourcefrog.net--2004/distcc--devel--2--patch-109/src/trace.h
> #if defined(HAVE_VARARG_MACROS)  && defined(__GNUC__)
> #define rs_log(l, s, str...) do {              \
>      rs_log0((l), __FUNCTION__, (s) , ##str);  \
>      } while (0)
> #else
> void rs_log0_nofn(int level, char const *fmt, ...);
> #define rs_log rs_log0_nofn
> #endif

That's something I considered, but it's a difficult choice between:

My trick:
 - Cannot be used in a situation where multiple statements without a
   block would be an error, such as the if() else example given
 - Gives the filename and line number

Downgrading to no filename/linenumber reporting on non-C99 compilers:
 - Corrupt stack could result in no way to determine program state at
   the time of the crash
 - Programmer is free to use error reporting routines regardless of

 - Jason                                                 Last known location: 

In a five year period we can get one superb programming language.  Only
we can't control when the five year period will begin.

More information about the linux-elitists mailing list