E
Erwin Lindemann
Hi group!
I found the following code in a free unix program and used it
successfully in a couple of programs. But for some reason it
does not compile under Windows.
Here's the code:
--------
#include <stdarg.h>
#include <stdio.h>
static int dbg_lvl = 0;
int dlevel(int lvl)
{
int prvlvl = dbg_lvl;
if(lvl < 0 || lvl > 7)
return -1;
dbg_lvl = lvl;
return prvlvl;
}
int dprintf(int lvl, const char *fmt, ...)
{
va_list ap;
int rv=0;
static char *s[] = {
"NONE", "INFO", "NOTICE", "WARNING",
"ERROR", "CRITICAL", "ALERT", "EMERG"
};
if(lvl <= dbg_lvl)
{
va_start(ap, fmt);
rv = fprintf(stderr, "%s: ", s[lvl]);
if(rv > 0) rv += vfprintf(stderr, fmt, ap);
va_end(ap);
}
return rv;
}
#define TEST
#ifdef TEST
int main(void)
{
int i;
dlevel(7);
for(i = 0; i <= 8; i++)
dprintf(i, "debug msg at level %d\n", i);
return 0;
}
#endif
--------
The error message from the Windows compiler is:
--------
Error dbg.c: 16 redefinition of 'dprintf'
Error c:\Programme\lcc\include\stdio.h: 133 Previous definition of 'dprintf' here
2 errors, 0 warnings
1 error
--------
I tried my best, but I can't find the problem.
Thanks,
Erwin Lindemann
I found the following code in a free unix program and used it
successfully in a couple of programs. But for some reason it
does not compile under Windows.
Here's the code:
--------
#include <stdarg.h>
#include <stdio.h>
static int dbg_lvl = 0;
int dlevel(int lvl)
{
int prvlvl = dbg_lvl;
if(lvl < 0 || lvl > 7)
return -1;
dbg_lvl = lvl;
return prvlvl;
}
int dprintf(int lvl, const char *fmt, ...)
{
va_list ap;
int rv=0;
static char *s[] = {
"NONE", "INFO", "NOTICE", "WARNING",
"ERROR", "CRITICAL", "ALERT", "EMERG"
};
if(lvl <= dbg_lvl)
{
va_start(ap, fmt);
rv = fprintf(stderr, "%s: ", s[lvl]);
if(rv > 0) rv += vfprintf(stderr, fmt, ap);
va_end(ap);
}
return rv;
}
#define TEST
#ifdef TEST
int main(void)
{
int i;
dlevel(7);
for(i = 0; i <= 8; i++)
dprintf(i, "debug msg at level %d\n", i);
return 0;
}
#endif
--------
The error message from the Windows compiler is:
--------
Error dbg.c: 16 redefinition of 'dprintf'
Error c:\Programme\lcc\include\stdio.h: 133 Previous definition of 'dprintf' here
2 errors, 0 warnings
1 error
--------
I tried my best, but I can't find the problem.
Thanks,
Erwin Lindemann