Monday, April 24, 2006

Tracing in linux

#include
#include

3 comments:

Ani said...

using va_list in functions, you can get variable number of arguments (Since it is in stdarg.h - it's standard, hence portable)- fine.

But to call a macro with variable number of args, either you must use ISO C99 standard compliant compiler, which allows something like
#define debug(format, ...)

Or use the GCC extension - which still supports variadic macros, but with a slightly different syntax.
#define debug(format, args...)

--
Ani

Ani said...

Definitely, you can use __FILE__ and __LINE__ as they are ANSI std.
But __FUNCTION__ is not! (still most compilers including gcc provide this as an extension)

What warnings could you not supress?

Generally, for logging functionalities, macros call external functions which can do various things, like log it to a local file, or transfer to a remote filesystems where logs are archived.

I dont see any efficiecy concerns here. Infact I've seen lots of such usage.

Ani said...

Reddy, just remembered this from CFAQ yesterday, actually, you can do away with double-parens '((' which is confusing and we have to remember to type in each time.

Instead, you can write the macro in a different way so that you dont need double-parens:

Sample:

#define DEBUG printf("\n%s:%d - %s: ", __FILE__, __LINE__, __FUNCTION__), printf

you can call the macro like

DEBUG ("Hello \n");

--
Ani