Build failures with -Werror=strict-prototypes
Opened this issue · 0 comments
orlitzky commented
If I attempt to build GKlib with -Werror=strict-prototypes
in my CFLAGS
, I get a few errors:
[ 2%] Building C object CMakeFiles/GKlib.dir/b64.c.o
/usr/bin/gcc -I/home/mjo/src/GKlib/. -I/home/mjo/src/GKlib/test -O2 -pipe -march=native -O0 -Werror=strict-prototypes -DLINUX -D_FILE_OFFSET_BITS=64 -std=c99 -fno-strict-aliasing -march=native -fPIC -Werror -Wall -pedantic -Wno-unused-function -Wno-unused-but-set-variable -Wno-unused-variable -Wno-unknown-pragmas -Wno-unused-label -DNDEBUG -DNDEBUG2 -DHAVE_EXECINFO_H -DHAVE_GETLINE -O3 -MD -MT CMakeFiles/GKlib.dir/b64.c.o -MF CMakeFiles/GKlib.dir/b64.c.o.d -o CMakeFiles/GKlib.dir/b64.c.o -c /home/mjo/src/GKlib/b64.c
In file included from /home/mjo/src/GKlib/GKlib.h:80,
from /home/mjo/src/GKlib/b64.c:20:
/home/mjo/src/GKlib/./gk_proto.h:114:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
114 | int gk_malloc_init();
| ^~~
/home/mjo/src/GKlib/./gk_proto.h:119:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
119 | size_t gk_GetCurMemoryUsed();
| ^~~~~~
/home/mjo/src/GKlib/./gk_proto.h:120:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
120 | size_t gk_GetMaxMemoryUsed();
| ^~~~~~
/home/mjo/src/GKlib/./gk_proto.h:122:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
122 | size_t gk_GetProcVmPeak();
| ^~~~~~
/home/mjo/src/GKlib/./gk_proto.h:141:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
141 | int gk_sigtrap();
| ^~~
/home/mjo/src/GKlib/./gk_proto.h:142:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
142 | int gk_siguntrap();
| ^~~
/home/mjo/src/GKlib/./gk_proto.h:144:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
144 | void gk_SetSignalHandlers();
| ^~~~
/home/mjo/src/GKlib/./gk_proto.h:145:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
145 | void gk_UnsetSignalHandlers();
| ^~~~
/home/mjo/src/GKlib/./gk_proto.h:148:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
148 | void PrintBackTrace();
| ^~~~
/home/mjo/src/GKlib/./gk_proto.h:279:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
279 | GK_MKRANDOM_PROTO(gk_c, size_t, char)
| ^~~~~~~~~~~~~~~~~
/home/mjo/src/GKlib/./gk_proto.h:280:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
280 | GK_MKRANDOM_PROTO(gk_i, size_t, int)
| ^~~~~~~~~~~~~~~~~
/home/mjo/src/GKlib/./gk_proto.h:281:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
281 | GK_MKRANDOM_PROTO(gk_i32, size_t, int32_t)
| ^~~~~~~~~~~~~~~~~
/home/mjo/src/GKlib/./gk_proto.h:282:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
282 | GK_MKRANDOM_PROTO(gk_f, size_t, float)
| ^~~~~~~~~~~~~~~~~
/home/mjo/src/GKlib/./gk_proto.h:283:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
283 | GK_MKRANDOM_PROTO(gk_d, size_t, double)
| ^~~~~~~~~~~~~~~~~
/home/mjo/src/GKlib/./gk_proto.h:284:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
284 | GK_MKRANDOM_PROTO(gk_idx, size_t, gk_idx_t)
| ^~~~~~~~~~~~~~~~~
/home/mjo/src/GKlib/./gk_proto.h:285:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
285 | GK_MKRANDOM_PROTO(gk_z, size_t, ssize_t)
| ^~~~~~~~~~~~~~~~~
/home/mjo/src/GKlib/./gk_proto.h:286:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
286 | GK_MKRANDOM_PROTO(gk_zu, size_t, size_t)
| ^~~~~~~~~~~~~~~~~
/home/mjo/src/GKlib/./gk_proto.h:312:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
312 | gk_csr_t *gk_csr_Create();
| ^~~~~~~~
/home/mjo/src/GKlib/./gk_proto.h:371:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
371 | gk_mcore_t *gk_gkmcoreCreate();
| ^~~~~~~~~~
/home/mjo/src/GKlib/./gk_proto.h:389:1: error: function declaration isn't a prototype [-Werror=strict-prototypes]
389 | gk_graph_t *gk_graph_Create();
| ^~~~~~~~~~
cc1: all warnings being treated as errors
Of course, I've shot myself in the foot by turning those warnings into errors, but there's a good reason to do it. The next version of the C language standard is going to invalidate those prototypes, leading (eventually) to build failures when people upgrade their compilers. We're trying to get out ahead of the problem:
- https://wiki.gentoo.org/wiki/Modern_C_porting
- https://fedoraproject.org/wiki/Changes/PortingToModernC
A quick glance at the errors above suggests that replacing ()
with (void)
and foo(...)
by int foo(...)
should be all it takes to make them future-proof.