Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MilanKlausz opened this issue Aug 2, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@MilanKlausz
Copy link
Contributor

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_EXTRA_CFLAGS=-Wno-strict-prototypes compillation flag (as suggested in madler/zlib#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;
}
@MilanKlausz MilanKlausz added the bug Something isn't working label Aug 2, 2023
@tkittel
Copy link
Member

tkittel commented Aug 2, 2023

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
Copy link
Contributor Author

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
Copy link
Member

tkittel commented Aug 2, 2023

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

@tkittel
Copy link
Member

tkittel commented Aug 2, 2023

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

@tkittel
Copy link
Member

tkittel commented Aug 2, 2023

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!

MilanKlausz referenced this issue in mctools/dgcode_val Aug 2, 2023
MilanKlausz referenced this issue in mctools/dgcode Aug 2, 2023
@tkittel tkittel transferred this issue from mctools/dgcode Feb 8, 2024
@tkittel
Copy link
Member

tkittel commented Feb 12, 2024

I guess we can close this now.

@tkittel tkittel closed this as completed Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants