473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Where is the error in this code?

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

Jan 22 '08 #1
5 1855
On Jan 22, 3:19*pm, Erwin Lindemann <elind...@wupp.invalidwrote:
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.
Call your routine Dprintf() instead of dprintf().
Jan 23 '08 #2
Randy Howard <ra*********@FOOverizonBAR.netwrites:
On Tue, 22 Jan 2008 17:31:02 -0600, Walter Roberson wrote
(in article <fn**********@canopus.cc.umanitoba.ca>):
>Windows has a non-standard routine named dprintf() that it declares
in its stdio.h . (There is also a dprintf() that is in the GNU glibc2
library.)

So they are broken in much the same way lcc-win32 is, as seen in a
recent thread.
Actually, I think the stdio.h file is provided by the compiler, not by
Windows. Note that the file name in the compiler's error message was
"c:\Programme\lcc\include\stdio.h".

The identifier "dprintf" is available for user code; if the
implementation interferes with this in conforming mode, that's a bug.
The OP should contact the compiler vendor.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jan 23 '08 #3
user923005 <dc*****@connx.comwrote:
On Jan 22, 3:19 pm, Erwin Lindemann <elind...@wupp.invalidwrote:
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
^^^
Call your routine Dprintf() instead of dprintf().
That's the wrong solution. The right solution is to use a conforming
implementation. This is the second such gaffe we've seen in a week.

Richard
Jan 23 '08 #4
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
user923005 <dc*****@connx.comwrote:
>On Jan 22, 3:19 pm, Erwin Lindemann <elind...@wupp.invalidwrote:
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
^^^
>Call your routine Dprintf() instead of dprintf().

That's the wrong solution. The right solution is to use a conforming
implementation. This is the second such gaffe we've seen in a week.
I agree that changing the name isn't a good solution, but it's a
reasonable short-term workaround. It's a lot easier than switching to
another compiler (which might have bugs of its own).

On the other hand, if you were thinking of switching compilers anyway,
this could be one more reason to do so.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jan 23 '08 #5
On Jan 23, 9:14*am, Keith Thompson <ks...@mib.orgwrote:
r...@hoekstra-uitgeverij.nl (Richard Bos) writes:
user923005 <dcor...@connx.comwrote:
On Jan 22, 3:19 pm, Erwin Lindemann <elind...@wupp.invalidwrote:
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
* * * * * * * * * * * *^^^
Call your routine Dprintf() instead of dprintf().
That's the wrong solution. The right solution is to use a conforming
implementation. This is the second such gaffe we've seen in a week.

I agree that changing the name isn't a good solution, but it's a
reasonable short-term workaround. *It's a lot easier than switching to
another compiler (which might have bugs of its own).

On the other hand, if you were thinking of switching compilers anyway,
this could be one more reason to do so.
Also, if the compiler is invoked in conforming mode and acts in a non-
conforming manner, issue a defect report to the compiler vendor with
enough information to reproduce the problem. Generally speaking, this
is a good way to increase the quality of software tools of any sort.
Jan 23 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: jabailo | last post by:
I wrote a program that loops through a file of records. It parses each line in the file and sends them to a web service that inserts them into an AS400DB2 database using Asynch calls. This is...
3
by: Tim Reynolds | last post by:
I support a .Net application running on a SERVER accessing MF Db2 data. Occasionally, we have some type of connection problem that we have been unable to debug up to this point. We typically...
1
by: Tom | last post by:
Suppose you have code structure like this: Option Explicit Dim MyVariable As Single Private Sub CallingProcedure() Call CalledProcedure() ....Do This ... End Sub Private Sub...
7
by: Mr. Mountain | last post by:
In the following code I simulate work being done on different threads by sleeping a couple methods for about 40 ms. However, some of these methods that should finish in about 40 -80 ms take as long...
7
by: Yongsub Eric Shin | last post by:
Hi. I'm just a beginner in ASP.Net. I started writing codes and I keep on getting this Runtime Error page, where it says "Description: An application error occurred on the server. The current...
10
by: Ray Stevens | last post by:
I am attempting to test a VeriSign account and the setup instructions stated that the certs file needed to go into the Windows\System32 folder. I am getting an error from the code-behind assebly...
3
by: Yannick | last post by:
Hi, I try to execute request on a ms-access database but I have a problem with date. the "myDate" field's format is "date/time" my request is: SELECT myCode, myStuff, myDATE FROM myTable ...
12
by: Yannick | last post by:
Hi, I've got a problem accessing a ms-access db with a sql statement like this: SELECT * FROM laTable WHERE laDate = #05/21/2004# ; with asp.net (vb code) laTable contains a "laDate"...
7
by: Swinky | last post by:
Mr. Browne's copy code on his web site has saved me. I have been struggling to copy a record with several related sub-form tables. I found code on his web site that copies a sub-form table,...
10
by: arial | last post by:
Hi, I am getting this error message: Incorrect syntax near the keyword 'where'. Description: An unhandled exception occurred during the execution of the current web request. Please review...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.