C Preprocessor problem

taklubaba's Avatar
Newbie Member
I have a piece of code as pasted below.

I get warnings like

test1.c:29:32: warning: pasting "(" and ""ERROR:"" does not give a valid preprocessing token
test1.c: In function `main':
test1.c:29: `__MODULE__' undeclared (first use in this function)
test1.c:29: (Each undeclared identifier is reported only once
test1.c:29: for each function it appears in.)

What does warning: pasting "(" and ""ERROR:"" does not give a valid preprocessing token mean?

And where is __MODULE__ defined?

Please provide me some solution.

#include <stdio.h>
#include <stdarg.h>

#define DL1 "%s:"
#define DR1 ,__MODULE__
#define DL2 "%d:"
#define DR2 ,__LINE__

void Trace(char *format, ...);

#define Debug(ARGS...) Trace(##ARGS)

#define Error(ARGS,...)   \
        Debug("ERROR:"DL1 DL2 ARGS "\n" DR1 DR2, ## __VA_ARGS__)

void Trace(char *format, ...){
	va_list args;
    va_start(args, format);
	vprintf(format, args);

	int i = 10;
	Error("Print from main");
	return 0;

Last edited by shabbir; 25Nov2008 at 09:02.. Reason: Code block
xpi0t0s's Avatar, Join Date: Aug 2004
Well there's some serious preprocessor abuse going on here...
You define Debug() as Trace, then Error as Debug, so Error is actually being defined as Trace().
When you use the ## pasting token, you need to provide two tokens to paste together, so Trace (##ARGS) makes no sense, and neither does DR2, ##__VA_ARGS__ a few lines later.
So possibly this is old code that worked on older compilers and needs fixing up for new compilers.
__MODULE__ and __LINE__ are defined by the preprocessor; __MODULE__ is the filename and __LINE__ is the current line number.