https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102442
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |egallager at gcc dot gnu.org
--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
That's not a C89 function parameter, that's a K&R-style parameter, which was
outdated even in C89. GCC warns about it:
$ /usr/local/bin/gcc -c -Wall -Wextra -Wstrict-prototypes -Wimplicit
-Wold-style-definition -Wold-style-declaration -Wmissing-prototypes
-Wmissing-declarations -pedantic -Wconversion -Wdouble-promotion
-Wtraditional-conversion 102442.c
102442.c:4:7: warning: function declaration isn't a prototype
[-Wstrict-prototypes]
4 | float fx(x) float x;
| ^~
102442.c: In function 'fx':
102442.c:4:7: warning: old-style function definition [-Wold-style-definition]
102442.c:6:14: warning: implicit conversion from 'float' to 'double' to match
other operand of binary expression [-Wdouble-promotion]
6 | return x + 1.0;
| ^
102442.c:6:14: warning: conversion from 'double' to 'float' may change value
[-Wfloat-conversion]
6 | return x + 1.0;
| ~~^~~~~
102442.c: At top level:
102442.c:9:7: warning: function declaration isn't a prototype
[-Wstrict-prototypes]
9 | float inita() { return 3.0; }
| ^~~~~
102442.c: In function 'inita':
102442.c:9:7: warning: old-style function definition [-Wold-style-definition]
102442.c: At top level:
102442.c:11:5: warning: function declaration isn't a prototype
[-Wstrict-prototypes]
11 | int main()
| ^~~~
102442.c: In function 'main':
102442.c:11:5: warning: old-style function definition [-Wold-style-definition]
In file included from 102442.c:1:
102442.c:14:15: warning: implicit conversion from 'float' to 'double' when
passing argument to function [-Wdouble-promotion]
14 | assert(fx(a) == 4.0);
| ^
102442.c:14:18: warning: implicit conversion from 'float' to 'double' to match
other operand of binary expression [-Wdouble-promotion]
14 | assert(fx(a) == 4.0);
| ^~
102442.c:14:5: warning: passing argument 1 of '__builtin_expect' with different
width due to prototype [-Wtraditional-conversion]
14 | assert(fx(a) == 4.0);
| ^~~~~~
102442.c:14:5: warning: passing argument 2 of '__builtin_expect' with different
width due to prototype [-Wtraditional-conversion]
$
As does clang:
$ clang -c -Weverything 102442.c
warning: include location '/usr/local/include' is unsafe for cross-compilation
[-Wpoison-system-directories]
102442.c:6:14: warning: implicit conversion loses floating-point precision:
'double' to 'float' [-Wimplicit-float-conversion]
return x + 1.0;
~~~~~~ ~~^~~~~
102442.c:6:12: warning: implicit conversion increases floating-point precision:
'float' to 'double' [-Wdouble-promotion]
return x + 1.0;
^ ~
102442.c:4:7: warning: no previous prototype for function 'fx'
[-Wmissing-prototypes]
float fx(x) float x;
^
102442.c:4:1: note: declare 'static' if the function is not intended to be used
outside of this translation unit
float fx(x) float x;
^
static
102442.c:4:9: warning: this old-style function definition is not preceded by a
prototype [-Wstrict-prototypes]
float fx(x) float x;
^
102442.c:9:7: warning: no previous prototype for function 'inita'
[-Wmissing-prototypes]
float inita() { return 3.0; }
^
102442.c:9:1: note: declare 'static' if the function is not intended to be used
outside of this translation unit
float inita() { return 3.0; }
^
static
102442.c:9:12: warning: this old-style function definition is not preceded by a
prototype [-Wstrict-prototypes]
float inita() { return 3.0; }
^
102442.c:14:12: warning: implicit conversion increases floating-point
precision: 'float' to 'double' [-Wdouble-promotion]
assert(fx(a) == 4.0);
^~~~~ ~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/assert.h:93:25:
note: expanded from macro 'assert'
(__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __FILE__, __LINE__, #e)
: (void)0)
^
102442.c:14:15: warning: implicit conversion increases floating-point
precision: 'float' to 'double' [-Wdouble-promotion]
assert(fx(a) == 4.0);
~~ ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/assert.h:93:25:
note: expanded from macro 'assert'
(__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __FILE__, __LINE__, #e)
: (void)0)
^
9 warnings generated.
$
I think the warnings make it pretty clear that code like this needs to be
updated.