I'm in the unfortunate position of trying to make a variadic macro (from Unix/Linux gcc code) work on OS/400 VRM510.

The macro is:

#define DEBUG_LOG(...) if (ch->flags & OTPW_DEBUG) \
{ fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); }


Note the use of ellipses in the macro definition. This makes the macro variadic and gives the 510 compiler a pink fit. The C compiler complains with:

CZM0211 Parameter list must be empty, or consist of one or more identifiers separated by commas.

The C++ compiler complains with:
"Expected an identifier but found "..." in the parameter list for the macro "DEBUG_LOG".

The C compiler documentation indicates that variadic macros and the __VA_ARGS__ identifier are supported at VRM530 and above but that doesn't help me :)

I'm posting this because perhaps someone who hates C less than I do may suggest a better solution.

I've tried a few things but I think the only way of making this work on 510 is to rewrite all 37 of the macro invocations to use a function which can then support the varying argument list. Something like:

#ifndef DEBUG_LOG
#if (__OS400_TGTVRM <= 520)
#define DEBUG_LOG if (ch->flags & OTPW_DEBUG)
#else
#define DEBUG_LOG(...) if (ch->flags & OTPW_DEBUG) \
{ fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); }
#endif
#endif



#if (__OS400_TGTVRM <= 520)
DEBUG_LOG debug_log( "Failed to change egid %d -> %d", oldgid, ch- >gid );
#else
DEBUG_LOG("Failed to change egid %d -> %d", oldgid, ch->gid);
#endif

and then provide a print function that handles a varying argument list:

#if (__OS400_TGTVRM <= 520)
void debug_log( char * f, ...)
{
va_list args;
va_start( args, f );
vfprintf(stderr, f, args)
va_end( args );
fputc('\n', stderr);
}
#endif

However, that strikes me as somewhat ugly so if you have better suggestions please fire away.

Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists

http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------




This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].