Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > CentOS and redhat

Reply
Thread Tools

CentOS and redhat

 
 
qianz99@gmail.com
Guest
Posts: n/a
 
      06-22-2007

I have a code. I can compile well in redhat. but when I swich to
CentOS
I ran into problems.
MAPlib.c:16: error: incompatible type for argument 1 of `log'

while my log is defined as
void log(FILE *fp,const char *fmt, ...)
{
if(!debugFlag) return;
va_list argp;
va_start(argp, fmt);
vfprintf(fp, fmt, argp);
va_end(argp);
}

What's the problem?

 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      06-22-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:

> I ran into problems.
> MAPlib.c:16: error: incompatible type for argument 1 of `log'


"log" is a function in the standard C library. It computes and
returns the natural logarithm of its floating-point argument.

> while my log is defined as
> void log(FILE *fp,const char *fmt, ...)
> {
> if(!debugFlag) return;
> va_list argp;


Only in C99 may declarations follow statements within a block.

> va_start(argp, fmt);
> vfprintf(fp, fmt, argp);
> va_end(argp);
> }


Attempting to define your own externally visible function named
"log" invokes undefined behavior. I'd suggest renaming your
function.
--
Ben Pfaff
http://benpfaff.org
 
Reply With Quote
 
 
 
 
Clever Monkey
Guest
Posts: n/a
 
      06-22-2007
(E-Mail Removed) wrote:
> I have a code. I can compile well in redhat. but when I swich to
> CentOS
> I ran into problems.
> MAPlib.c:16: error: incompatible type for argument 1 of `log'
>
> while my log is defined as
> void log(FILE *fp,const char *fmt, ...)
> {
> if(!debugFlag) return;
> va_list argp;
> va_start(argp, fmt);
> vfprintf(fp, fmt, argp);
> va_end(argp);
> }
>

Probably off-topic given the subject, but it may be that log() is not in
scope, or you are passing it something other than a FILE. Since you
show no relevant code, it's hard to tell.

Can you reduce the problem to the smallest reproduceable (i.e.,
compilable) case?
--
clvrmnky <(E-Mail Removed)>

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      06-22-2007
In article <(E-Mail Removed). com>,
<(E-Mail Removed)> wrote:

>MAPlib.c:16: error: incompatible type for argument 1 of `log'


There's a standard C function called log, for logarithms.
Unfortunately that means you have to call your function something
else.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
 
Reply With Quote
 
Clever Monkey
Guest
Posts: n/a
 
      06-22-2007
Richard Tobin wrote:
> In article <(E-Mail Removed). com>,
> <(E-Mail Removed)> wrote:
>
>> MAPlib.c:16: error: incompatible type for argument 1 of `log'

>
> There's a standard C function called log, for logarithms.
> Unfortunately that means you have to call your function something
> else.
>

D'oh! Of course.
--
clvrmnky <(E-Mail Removed)>

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      06-22-2007
(E-Mail Removed) wrote:
>
> I have a code. I can compile well in redhat. but when I swich to
> CentOS I ran into problems.
> MAPlib.c:16: error: incompatible type for argument 1 of `log'
>
> while my log is defined as
> void log(FILE *fp,const char *fmt, ...)
> {
> if(!debugFlag) return;
> va_list argp;
> va_start(argp, fmt);
> vfprintf(fp, fmt, argp);
> va_end(argp);
> }
>
> What's the problem?


Move the declaration of va_list up one line.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      06-22-2007
CBFalconer <(E-Mail Removed)> writes:
> (E-Mail Removed) wrote:
>>
>> I have a code. I can compile well in redhat. but when I swich to
>> CentOS I ran into problems.
>> MAPlib.c:16: error: incompatible type for argument 1 of `log'
>>
>> while my log is defined as
>> void log(FILE *fp,const char *fmt, ...)
>> {
>> if(!debugFlag) return;
>> va_list argp;
>> va_start(argp, fmt);
>> vfprintf(fp, fmt, argp);
>> va_end(argp);
>> }
>>
>> What's the problem?

>
> Move the declaration of va_list up one line.


And why would you expect that to solve "error: incompatible type for
argument 1 of `log'"?

Yes, he should move the declaration of argp up a line if he doesn't
want to depend on either a C99 compiler or a C90 compiler with
extensions, but the real problem seems to be a name collision with the
"log" function declared in <math.h>.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Barry Schwarz
Guest
Posts: n/a
 
      06-23-2007
On Fri, 22 Jun 2007 16:30:40 -0000, (E-Mail Removed) wrote:

>
>I have a code. I can compile well in redhat. but when I swich to
>CentOS
>I ran into problems.
>MAPlib.c:16: error: incompatible type for argument 1 of `log'
>
>while my log is defined as
>void log(FILE *fp,const char *fmt, ...)
>{
> if(!debugFlag) return;
> va_list argp;
> va_start(argp, fmt);
> vfprintf(fp, fmt, argp);
> va_end(argp);
>}
>
>What's the problem?


The error message probably relates to the statement that calls log.
The code you have shown only has parameters, not arguments. We also
need to see the prototype, if any, for log before the function is
defined (in case the compiler diagnostic is using less than precise
terminology).


Remove del for email
 
Reply With Quote
 
Barry Schwarz
Guest
Posts: n/a
 
      06-23-2007
On Fri, 22 Jun 2007 09:57:07 -0700, Ben Pfaff <(E-Mail Removed)>
wrote:

>(E-Mail Removed) writes:
>
>> I ran into problems.
>> MAPlib.c:16: error: incompatible type for argument 1 of `log'

>
>"log" is a function in the standard C library. It computes and
>returns the natural logarithm of its floating-point argument.
>
>> while my log is defined as
>> void log(FILE *fp,const char *fmt, ...)
>> {
>> if(!debugFlag) return;
>> va_list argp;

>
>Only in C99 may declarations follow statements within a block.
>
>> va_start(argp, fmt);
>> vfprintf(fp, fmt, argp);
>> va_end(argp);
>> }

>
>Attempting to define your own externally visible function named
>"log" invokes undefined behavior. I'd suggest renaming your
>function.


And to clever monkey, Richard Tobin, and Keith Thompson: There is no
indication that his program contained a #include<math.h> directive.
Without it, there would be no prototype in scope for the standard log
function and the compiler should not be able to match the calling
statement or this function definition to that standard function. A
linker message regarding multiply defined functions with the same name
or a run time error (including any type of undefined behavior) because
the wrong function was called should be the worst that this situation
could produce. A compile time error about argument mismatches just
doesn't seem to flow from this situation.


Remove del for email
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      06-23-2007
Barry Schwarz <(E-Mail Removed)> writes:
> On Fri, 22 Jun 2007 09:57:07 -0700, Ben Pfaff <(E-Mail Removed)>
> wrote:
>>(E-Mail Removed) writes:
>>> I ran into problems.
>>> MAPlib.c:16: error: incompatible type for argument 1 of `log'

>>
>>"log" is a function in the standard C library. It computes and
>>returns the natural logarithm of its floating-point argument.
>>
>>> while my log is defined as
>>> void log(FILE *fp,const char *fmt, ...)
>>> {
>>> if(!debugFlag) return;
>>> va_list argp;

>>
>>Only in C99 may declarations follow statements within a block.
>>
>>> va_start(argp, fmt);
>>> vfprintf(fp, fmt, argp);
>>> va_end(argp);
>>> }

>>
>>Attempting to define your own externally visible function named
>>"log" invokes undefined behavior. I'd suggest renaming your
>>function.

>
> And to clever monkey, Richard Tobin, and Keith Thompson: There is no
> indication that his program contained a #include<math.h> directive.
> Without it, there would be no prototype in scope for the standard log
> function and the compiler should not be able to match the calling
> statement or this function definition to that standard function. A
> linker message regarding multiply defined functions with the same name
> or a run time error (including any type of undefined behavior) because
> the wrong function was called should be the worst that this situation
> could produce. A compile time error about argument mismatches just
> doesn't seem to flow from this situation.


Since log is a predefined function, the compiler may know about it.
I've seen compilers (or at least one) use such knowledge to optimize
certain calls, or to diagnose invalid format strings for printf.
Since the code failed to compile, there was no opportunity for a link
error to appear.

Since the OP didn't show us a complete program, it's entirely possible
that <math.h> is included, either directly or indirectly. It's also
not clear that the declaration for the OP's own log function was
visible at the point of the call.

And the function's name needs to be changed anyway.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python vs. Fedora and CentOS John Nagle Python 15 06-02-2010 05:40 AM
Does Paramiko 1.7.2 and 1.6.4 work with CentOS 4 Shah Sultan Alam Python 1 02-25-2009 06:38 AM
Compiling ruby-1.8.6 on CentOS-4.5 with readline and openssl James Byrne Ruby 4 09-07-2007 05:41 PM
Can someone try this on RedHat Linux/jre1.5 or redhat linux/jdk1.6? U. George Java 4 08-11-2005 12:33 PM
Python RPM and CentOS rbt Python 2 05-17-2005 02:54 PM



Advertisments