× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Simon Coulter wrote:

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:


Simon, here's a way using text-substitution that's a bit carsick-making, but it works:

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

The debug_chk() function would log the true/false value in a global variable and then the debug_log() function would check the global before doing the fprintf.

Here's my code:

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

#define OTPW_DEBUG 1
#define DEBUG_LOG debug_chk(ch->flags & OTPW_DEBUG);debug_log

static int g_flag = 0;

void debug_chk(int flag)
{
g_flag = flag;
}

void debug_log( char * f, ...)
{
va_list args;
if (g_flag)
{
va_start( args, f );
vfprintf(stderr, f, args)
va_end( args );
fputc('\n', stderr);
}
}

main()
{
typedef struct
{
int flags;
} ch_t;
ch_t the_ch = {0xffffffff};
ch_t *ch = &the_ch;
DEBUG_LOG("hello");
DEBUG_LOG("there are %d %s", 2, "worlds");
DEBUG_LOG("hello %s", "world");
}

As an Amazon Associate we earn from qualifying purchases.

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-2024 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].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.