[flac-dev] GCC/clang compilation issues

Erik de Castro Lopo mle+la at mega-nerd.com
Sun Dec 7 23:44:39 PST 2014


Oliver Stöneberg wrote:

> And I am willing to looking at FLAC and spent my time to fix compiler 
> warnings to make it more portable and fixing potential issue and you 
> are being such a dick to me.

I will be the first to admit that I am far from perfect, but I think
I have shown considerable constraint. If any of my responses have been
out of line I'm sure one of the regular contributors would have already
said so to me privately or in fact will do so now. We will see.

> As mentioned in my first mail I have 
> some patches lined up.
> Very smart move to turn off a external contributor.

The fact that there are at least 10 people on this list who have
contributed at least one patch (and some very much more) in the
last year shows that I can't be all that hard to deal with.

> Also I mentioned in my first mail, that I have no idea what the 
> intention of that code is, so maybe just telling that instead of 
> telling me might have given me the change to fix it myself and then 
> submit that.

Before you fix anything, you need to check whether there is any
warning with your compiler and our build system. If there is no
such warning they may actually not be anything to fix.

Anyway, thinking I may have actually been in the wrong here I went
back to your original email and the problem you reported:

    src/lib/libflac/libFLAC/stream_encoder.c:1696:43: error: cast from function call
          of type 'double' to non-matching type 'FLAC__int32' (aka 'int')
      [-Werror,-Wbad-function-cast]
      ...FLAC__int32 tukey_parts = (FLAC__int32)strtod(specification+14, 0);

The warning arises from the -Wbad-function-cast warning flag. If you
look in our configure.ac file you will see that is a warning flag
that the FLAC build system does *not* use. That warning flag is
enabled by *your* build system to it is 100% your problem to deal
with.

Secondly, the code it is warning about is this:

    FLAC__int32 tukey_parts = (FLAC__int32)strtod(specification+14, 0);

The type of strtod is:

    double strtod(const char *nptr, char **endptr);

it takes a string and returns a double. The FLAC code takes that double,
casts it to an int. The FLAC code base nearly always makes casts from
double to int explicit.

The Clang man page doesn't document the -Wbad-function-cast warning flag,
but the GCC man page says the following:

    -Wbad-function-cast (C and Objective-C only)
       Warn whenever a function call is cast to a non-matching type. For
       example, warn if "int malloc()" is cast to "anything *".

Like I said, this is not a warning that the FLAC build system uses, because
we see that warning as being of little use. Furthermore that documentation
is weird because the ISO C Standard says the malloc has type

    void *malloc(size_t size);

and the thing being cast is not the function call, but the function's return
value.

Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/


More information about the flac-dev mailing list