dethrace-labs / dethrace

Reverse engineering the 1997 game "Carmageddon"
https://twitter.com/dethrace_labs
GNU General Public License v3.0
669 stars 38 forks source link

Adds (void) to all functions taking no args #318

Closed dethrace-labs closed 1 year ago

dethrace-labs commented 1 year ago

This was necessary to make the latest main compile in my OSX environment (clang-14.0.3).

Otherwise, I was seeing error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes] for all void functions

madebr commented 1 year ago

I think this is the wrong approach to fix the error. We need to be careful to declare public symbols in headers, declare private symbols in the source file, and add static to the private ones. ODR for C. I did something similar for private symbols in the -Wstrict-prototypes pr. We should also get rid of all extern function declarations in c sources, such as here. These declarations can get out of sync.

It looks like the warnings you're seeing are warnings emitted by -Wmissing-declarations on gcc

  -Wmissing-declarations
      Warn if a global function is defined without a previous declaration.  Do so even if the definition
      itself provides a prototype.  Use this option to detect global functions that are not declared in header
      files.  In C, no warnings are issued for functions with previous non-prototype declarations; use
      -Wmissing-prototypes to detect missing prototypes.  In C++, no warnings are issued for function
      templates, or for inline functions, or for functions in anonymous namespaces.

example: the following example will emit the warning you're seeing. The fix is to add #include <a.h> to a.c. That way we are sure a.h and a.c remain in sync.

a.h

int my_function(void);

a.c

// no #include <a.h>
int my_function() {
  return arg + 2;
}
dethrace-labs commented 1 year ago

Right, yep, agree with your points 👍

But take a look at BRSRC/DOSIO/eventq.c|h (this was the first file that started complaining).

the .h file contains br_error DOSEventBegin(void);, while the .c file has br_error DOSEventBegin() { .. }

Adding the void argument to the .c file fixes the error, presumably because otherwise the signatures do not match?

madebr commented 1 year ago

I notice my IDE (=clion) also shows this warning when I hover over DosEventEnd(). Let's apply this one, and in a future pr do an effort to make the code compatible with -Wmissing-declarations.