"fe*****@gmail.com" wrote:
fe*****@gmail.com wrote:
#define ONCFILE_ERR1(funcname, name) \
{ \
#ifdef DEBUG\
cerr << __FILE__ << ":" << __LINE__ << " duplicated call to " <<
funcname << " " << name << endl; \
#endif \
}
I want to have conditional macros inside a macro. When I compile
this code, the error message is:
ONetCDFFile.cpp:14:2: '#' is not followed by a macro parameter
Any idea how I should proceed with this?
another question about macro, how do i force a return at the end
of each macro line? it seems the end result of multi-line macro
always colapse into a single line...
Don't toppost. Your answer (or continuation) belongs after (or
intermixed with) the material you quote, after snipping irrelevant
material. I fixed this one.
You can't do that.
Ignoring the C++, and just considering macros (which are common to
C++ and C). By definition a macro (the part after the #define)
ends on the same line. This can be partially ameliorated by the
use of continuation lines (where the last character on the physical
line is a '\'). You CANNOT put preprocessing conditionals inside a
macro, because they have to start a line, and you can't get there
without ending the macro definition.
The usual trick to form multiline macros is the following:
#define MULTILINEMACRO \
do { \
statement1; \
statement2; \
} while (0)
Notice no final semicolon. The limit is the maximum input line the
compiler can handle, which is guaranteed about 500 for C90. Look
it up. This behaves properly for all macros that do not have to
return a value.
In future please ask C++ questions on c.l.c++, and C questions on
c.l.c. Don't toppost on either newsgroup.
--
Read about the Sony stealthware that is a security leak, phones
home, and is generally illegal in most parts of the world. Also
the apparent connivance of the various security software firms.
http://www.schneier.com/blog/archive...drm_rootk.html