CentOS and redhat

Discussion in 'C Programming' started by qianz99@gmail.com, Jun 22, 2007.

  1. Guest

    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?
     
    , Jun 22, 2007
    #1
    1. Advertising

  2. Ben Pfaff Guest

    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
     
    Ben Pfaff, Jun 22, 2007
    #2
    1. Advertising

  3. 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 <mailto:>

    Direct replies will be blacklisted. Replace "spamtrap" with my name to
    contact me directly.
     
    Clever Monkey, Jun 22, 2007
    #3
  4. In article <>,
    <> 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.
     
    Richard Tobin, Jun 22, 2007
    #4
  5. Richard Tobin wrote:
    > In article <>,
    > <> 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 <mailto:>

    Direct replies will be blacklisted. Replace "spamtrap" with my name to
    contact me directly.
     
    Clever Monkey, Jun 22, 2007
    #5
  6. CBFalconer Guest

    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
     
    CBFalconer, Jun 23, 2007
    #6
  7. CBFalconer <> writes:
    > 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) <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"
     
    Keith Thompson, Jun 23, 2007
    #7
  8. On Fri, 22 Jun 2007 16:30:40 -0000, 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
     
    Barry Schwarz, Jun 23, 2007
    #8
  9. On Fri, 22 Jun 2007 09:57:07 -0700, Ben Pfaff <>
    wrote:

    > 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
     
    Barry Schwarz, Jun 23, 2007
    #9
  10. Barry Schwarz <> writes:
    > On Fri, 22 Jun 2007 09:57:07 -0700, Ben Pfaff <>
    > wrote:
    >> 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) <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"
     
    Keith Thompson, Jun 23, 2007
    #10
  11. In article <>,
    Keith Thompson <> wrote:

    >Since the OP didn't show us a complete program, it's entirely possible
    >that <math.h> is included, either directly or indirectly.


    Since the OP said that the behaviour changed when switching between
    operating systems, my guess would be that one of them indirectly
    includes <math.h> and the other doesn't.

    -- Richard

    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
     
    Richard Tobin, Jun 23, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. U. George
    Replies:
    4
    Views:
    880
    U. George
    Aug 11, 2005
  2. rbt

    Python RPM and CentOS

    rbt, May 16, 2005, in forum: Python
    Replies:
    2
    Views:
    397
    Ken Godee
    May 17, 2005
  3. Shah Sultan Alam
    Replies:
    1
    Views:
    911
    Jason Scheirer
    Feb 25, 2009
  4. John Nagle

    Python vs. Fedora and CentOS

    John Nagle, May 29, 2010, in forum: Python
    Replies:
    15
    Views:
    3,307
    John Nagle
    Jun 2, 2010
  5. James Byrne
    Replies:
    4
    Views:
    221
    James Byrne
    Sep 7, 2007
Loading...

Share This Page