Removing GCC compiler warnings from fabsf(), sqrtf()...

Discussion in 'C Programming' started by Charlie Zender, Jan 2, 2004.

  1. Hi,

    First, this may be a GCC or Linux-specific problem, I'm not sure.

    I am unable to compile a large body of code with extremely pedantic
    compile time checks activate, so that warnings cause errors.
    With GCC 3.3.1, I do this with

    gcc -I/usr/local/include -g -O2 -std=c99 -pedantic -pedantic
    -D_BSD_SOURCE -Wall -Wunused -W -Wmissing-prototypes -Wconversion
    -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings
    bug.c -o bug -lm

    (This is basically what GSL recommendsd for scientific codes.)

    The current problem I have is that the following code (bug.c)

    #include <stdio.h>
    #include <math.h>
    int main()
    {
    /* float fabsf(float); */
    float foo,bar=-9;
    foo=fabsf(bar);
    fprintf(stdout,"foo = %g\n",foo);
    }

    produces this warning:

    bug.c:7: warning: passing arg 1 of `fabsf' as `float' rather than
    `double' due to prototype

    _regardless_ of whether the correct fabsf() prototype
    (float fabsf(float);) is commented out or not.
    Yes, my GNU/Linux system does have fabsf() etc. in libm.a.
    Yes, the intrinsics powf(), fabsf(), sqrtf()... cause the same warning.

    1. How do I use powf(), fabsf(), sqrtf() etc. with causing compiler
    warnings with the above compiler switches?

    Thanks to all who have answered my previous three posts!
    You've helped me de-lint 90% of my code...if I can fix this
    present problem then compiling it with -Werror should work
    and thus make catching new bugs at compile time much easier.

    Any help appreciated,
    Charlie
    --
    Charlie Zender, , (949) 824-2987, Department of Earth
    System Science, University of California, Irvine CA 92697-3100
    Visiting NCAR 12/13/03--1/17/04: ***********************************
    Voice/FAX: (303) 497-1724/1348, Office: Mesa Lab 259b **************
     
    Charlie Zender, Jan 2, 2004
    #1
    1. Advertising

  2. Charlie Zender wrote:

    > Hi,
    >
    > First, this may be a GCC or Linux-specific problem, I'm not sure.
    >
    > I am unable to compile a large body of code with extremely pedantic
    > compile time checks activate, so that warnings cause errors.
    > With GCC 3.3.1, I do this with
    >
    > gcc -I/usr/local/include -g -O2 -std=c99 -pedantic -pedantic
    > -D_BSD_SOURCE -Wall -Wunused -W -Wmissing-prototypes -Wconversion
    > -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings
    > bug.c -o bug -lm


    This appears to be a gcc issue, not a C issue, which makes it off-topic
    in comp.lang.c.

    >
    > (This is basically what GSL recommendsd for scientific codes.)
    >
    > The current problem I have is that the following code (bug.c)
    >
    > #include <stdio.h>
    > #include <math.h>
    > int main()
    > {
    > /* float fabsf(float); */
    > float foo,bar=-9;
    > foo=fabsf(bar);
    > fprintf(stdout,"foo = %g\n",foo);
    > }
    >
    > produces this warning:
    >
    > bug.c:7: warning: passing arg 1 of `fabsf' as `float' rather than
    > `double' due to prototype


    This warning appears to be a result of the -Wconversion option. You
    should probably read up on what the options you are using do.
    -Wconversion doesn't look like a good one to use in general (and may be
    completely useless in c99 mode).

    >
    > _regardless_ of whether the correct fabsf() prototype
    > (float fabsf(float);) is commented out or not.


    The correct prototype is in <math.h>. You should almost never provide
    prototypes for standard functions.

    > Yes, my GNU/Linux system does have fabsf() etc. in libm.a.
    > Yes, the intrinsics powf(), fabsf(), sqrtf()... cause the same warning.
    >
    > 1. How do I use powf(), fabsf(), sqrtf() etc. with causing compiler
    > warnings with the above compiler switches?


    That would seem to be impossible. -Wconversion will result in a warning
    for absolutely any code that calls a function that takes a 'float' (or
    'short' or 'char'), if I understand correctly.

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
     
    Kevin Goodsell, Jan 2, 2004
    #2
    1. Advertising

  3. Kevin Goodsell wrote:

    >
    > The correct prototype is in <math.h>. You should almost never provide
    > prototypes for standard functions.
    >


    I should clarify this. You should almost never provide prototypes for
    standard functions any way other than by #including the correct standard
    header.

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
     
    Kevin Goodsell, Jan 2, 2004
    #3
  4. Charlie Zender wrote:
    >
    > Hi,
    >
    > First, this may be a GCC or Linux-specific problem, I'm not sure.
    >
    > I am unable to compile a large body of code with extremely pedantic
    > compile time checks activate, so that warnings cause errors.
    > With GCC 3.3.1, I do this with
    >
    > gcc -I/usr/local/include -g -O2 -std=c99 -pedantic -pedantic
    > -D_BSD_SOURCE -Wall -Wunused -W -Wmissing-prototypes -Wconversion
    > -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings
    > bug.c -o bug -lm
    >
    > (This is basically what GSL recommendsd for scientific codes.)
    >
    > The current problem I have is that the following code (bug.c)
    >
    > #include <stdio.h>
    > #include <math.h>
    > int main()
    > {
    > /* float fabsf(float); */
    > float foo,bar=-9;
    > foo=fabsf(bar);
    > fprintf(stdout,"foo = %g\n",foo);
    > }
    >
    > produces this warning:
    >
    > bug.c:7: warning: passing arg 1 of `fabsf' as `float' rather than
    > `double' due to prototype
    >
    > _regardless_ of whether the correct fabsf() prototype
    > (float fabsf(float);) is commented out or not.
    > Yes, my GNU/Linux system does have fabsf() etc. in libm.a.
    > Yes, the intrinsics powf(), fabsf(), sqrtf()... cause the same warning.
    >
    > 1. How do I use powf(), fabsf(), sqrtf() etc. with causing compiler
    > warnings with the above compiler switches?
    >
    > Thanks to all who have answered my previous three posts!
    > You've helped me de-lint 90% of my code...if I can fix this
    > present problem then compiling it with -Werror should work
    > and thus make catching new bugs at compile time much easier.
    >
    > Any help appreciated,
    > Charlie
    > --
    > Charlie Zender, , (949) 824-2987, Department of Earth
    > System Science, University of California, Irvine CA 92697-3100
    > Visiting NCAR 12/13/03--1/17/04: ***********************************
    > Voice/FAX: (303) 497-1724/1348, Office: Mesa Lab 259b **************


    When you write
    float func1(float);

    float ff, gg;
    ...
    ff = func1(gg);

    the compiler will probably still promote gg to a double in the call to
    func1 unless your compiler has a switch that specifies not to perform
    such promotions.

    I have long ago decided never to use floats in a C program - much
    simpler and less hassle to always use doubles.
    --
    Fred L. Kleinschmidt
    Boeing Associate Technical Fellow
    Technical Architect, Common User Interface Services
    M/S 2R-94 (206)544-5225
     
    Fred L. Kleinschmidt, Jan 2, 2004
    #4
  5. Thanks for the insight. This is very consistent with what's happening.
    If true, then there is probably no viable workaround for me.

    Charlie

    > When you write
    > float func1(float);
    >
    > float ff, gg;
    > ...
    > ff = func1(gg);
    >
    > the compiler will probably still promote gg to a double in the call to
    > func1 unless your compiler has a switch that specifies not to perform
    > such promotions.
    >
    > I have long ago decided never to use floats in a C program - much
    > simpler and less hassle to always use doubles.



    --
    Charlie Zender, , (949) 824-2987, Department of Earth
    System Science, University of California, Irvine CA 92697-3100
    Visiting NCAR 12/13/03--1/17/04: ***********************************
    Voice/FAX: (303) 497-1724/1348, Office: Mesa Lab 259b **************
     
    Charlie Zender, Jan 3, 2004
    #5
  6. On Fri, 2 Jan 2004 23:39:11 GMT, "Fred L. Kleinschmidt"
    <fred.l.kleinschmidt@nospam_boeing.com> wrote:

    >
    >
    >Charlie Zender wrote:
    >>
    >> Hi,
    >>
    >> First, this may be a GCC or Linux-specific problem, I'm not sure.
    >>
    >> I am unable to compile a large body of code with extremely pedantic
    >> compile time checks activate, so that warnings cause errors.
    >> With GCC 3.3.1, I do this with
    >>
    >> gcc -I/usr/local/include -g -O2 -std=c99 -pedantic -pedantic
    >> -D_BSD_SOURCE -Wall -Wunused -W -Wmissing-prototypes -Wconversion
    >> -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings
    >> bug.c -o bug -lm
    >>
    >> (This is basically what GSL recommendsd for scientific codes.)
    >>
    >> The current problem I have is that the following code (bug.c)
    >>
    >> #include <stdio.h>
    >> #include <math.h>
    >> int main()
    >> {
    >> /* float fabsf(float); */
    >> float foo,bar=-9;
    >> foo=fabsf(bar);
    >> fprintf(stdout,"foo = %g\n",foo);
    >> }
    >>
    >> produces this warning:
    >>
    >> bug.c:7: warning: passing arg 1 of `fabsf' as `float' rather than
    >> `double' due to prototype
    >>
    >> _regardless_ of whether the correct fabsf() prototype
    >> (float fabsf(float);) is commented out or not.
    >> Yes, my GNU/Linux system does have fabsf() etc. in libm.a.
    >> Yes, the intrinsics powf(), fabsf(), sqrtf()... cause the same warning.
    >>
    >> 1. How do I use powf(), fabsf(), sqrtf() etc. with causing compiler
    >> warnings with the above compiler switches?
    >>
    >> Thanks to all who have answered my previous three posts!
    >> You've helped me de-lint 90% of my code...if I can fix this
    >> present problem then compiling it with -Werror should work
    >> and thus make catching new bugs at compile time much easier.
    >>
    >> Any help appreciated,
    >> Charlie
    >> --
    >> Charlie Zender, , (949) 824-2987, Department of Earth
    >> System Science, University of California, Irvine CA 92697-3100
    >> Visiting NCAR 12/13/03--1/17/04: ***********************************
    >> Voice/FAX: (303) 497-1724/1348, Office: Mesa Lab 259b **************

    >
    >When you write
    > float func1(float);
    >
    > float ff, gg;
    > ...
    > ff = func1(gg);
    >
    >the compiler will probably still promote gg to a double in the call to
    >func1 unless your compiler has a switch that specifies not to perform
    >such promotions.


    It better not. The only time floats are implicitly converted to
    doubles is for variadic functions.

    >
    >I have long ago decided never to use floats in a C program - much
    >simpler and less hassle to always use doubles.




    <<Remove the del for email>>
     
    Barry Schwarz, Jan 3, 2004
    #6
  7. Charlie Zender

    Ben Pfaff Guest

    Barry Schwarz <> writes:

    > It better not. The only time floats are implicitly converted to
    > doubles is for variadic functions.


    Expressions: 1.0f + 1;
    Initializations: double foo = 1.0f;
    Assignments: foo = 1.0f;
    etc.
     
    Ben Pfaff, Jan 3, 2004
    #7
  8. "Ben Pfaff" <> wrote in message
    news:...
    > Barry Schwarz <> writes:
    >
    > > It better not. The only time floats are implicitly converted to
    > > doubles is for variadic functions.

    >
    > Expressions: 1.0f + 1;


    This expression has type float.

    > Initializations: double foo = 1.0f;
    > Assignments: foo = 1.0f;
    > etc.


    --
    Peter
     
    Peter Nilsson, Jan 4, 2004
    #8
  9. Charlie Zender

    Ben Pfaff Guest

    "Peter Nilsson" <> writes:

    > "Ben Pfaff" <> wrote in message
    > news:...
    > > Barry Schwarz <> writes:
    > >
    > > > It better not. The only time floats are implicitly converted to
    > > > doubles is for variadic functions.

    > >
    > > Expressions: 1.0f + 1;

    >
    > This expression has type float.


    Excuse me, I meant 1.0f + 1.0.
    --
    A competent C programmer knows how to write C programs correctly,
    a C expert knows enough to argue with Dan Pop, and a C expert
    expert knows not to bother.
     
    Ben Pfaff, Jan 4, 2004
    #9
    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. Charlie Zender
    Replies:
    12
    Views:
    1,084
    Peter Pichler
    Jan 3, 2004
  2. Torsten Bronger

    Removing a warnings filter?

    Torsten Bronger, Jun 3, 2005, in forum: Python
    Replies:
    2
    Views:
    278
    Torsten Bronger
    Jun 4, 2005
  3. Warnings with gcc

    , Nov 22, 2005, in forum: C Programming
    Replies:
    34
    Views:
    1,380
    Flash Gordon
    Nov 25, 2005
  4. asdf

    gcc warnings

    asdf, Jun 26, 2006, in forum: C++
    Replies:
    4
    Views:
    373
  5. Ted Sung
    Replies:
    1
    Views:
    313
    Sherm Pendley
    Aug 30, 2004
Loading...

Share This Page