mctools / simplebuild-dgcode

dgcode: the Geant4-based simulation framework of the ESS Detector Group. Provided as simple-build-system bundles.
https://mctools.github.io/simplebuild-dgcode/
Other
2 stars 1 forks source link

A function declaration without a prototype is deprecated in all versions of C #17

Closed MilanKlausz closed 7 months ago

MilanKlausz commented 1 year ago

After upgrading to XCode 14.3 (requires macOS Ventura 13.0 or later), I get a lot of compillation errors (warnings treated as errors) saying "A function declaration without a prototype is deprecated in all versions of C". This is because "C2x will be removing support for functions with identifier lists, and will be changing the behavior of prototypeless functions with empty parentheses to match the behavior of C++" (from link)

A lot of functions in MiniZLib use the now unsupported identifier lists (a part of K&R-style function definition syntax). The errors/warnings could be silenced by using _DG_EXTRACFLAGS=-Wno-strict-prototypes compillation flag (as suggested in https://github.com/madler/zlib/issues/633 ), but for us it would be better to change the function definitions:

int foo(s, f)
  char* s;
  float f;
{
  return 5;
}

to

int foo(char* s, float f)
{
  return 5;
}

Also, for similar reason, empty parameter lists should be given an explicit parameter of void:

int foo()
{
  return 5;
}

to

int foo(void)
{
  return 5;
}
tkittel commented 1 year ago

Are you actually sure that we also get compilation errors with the empty parameter lists? Because those I imagine we have a whole bunch of, and honestly the int foo(void) form is damn ugly.

MilanKlausz commented 1 year ago

Yes, the error messages are quite explicit e.g.:

/Users/milanklausz/dgcode_val/.bld/pkgs/MCPL/libsrc/mcpl.c:223:39: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void mcpl_platform_compatibility_check() {
                                      ^
                                       void

I even read somewhere that in the backgroung "int foo()" is actually using the K&R-style function definition syntax (with an empty identifier lists), not an empty parameter list, but I can't find the reference now. Here is another source, though: "The special case of an unnamed parameter of type void as the only item in the list specifies that the function has no parameters."

tkittel commented 1 year ago

Ok, got it! In that case I will update the functions with no arguments in ncrystaldev / .. / ncrystal.h as well.

tkittel commented 1 year ago

However, I hope that this does not apply to argument-less functions in C++ code inside extern "C" blocks!

tkittel commented 1 year ago

To answer myself: I think argument-less functions in C++ code inside extern "C" blocks must be fine, because it is still C++ in that file!

tkittel commented 7 months ago

I guess we can close this now.