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

Require use of Modern C #339

Closed
david-a-wheeler opened this issue Dec 9, 2023 · 3 comments
Closed

Require use of Modern C #339

david-a-wheeler opened this issue Dec 9, 2023 · 3 comments

Comments

@david-a-wheeler
Copy link
Contributor

david-a-wheeler commented Dec 9, 2023

It's possible to use flags to enforce use if "modern" C (C89 or later). More info here:

https://fedoraproject.org/wiki/Changes/PortingToModernC

Perhaps those should be added. Some changes may cause autoconf problems, we shoukd document how to address them, e.g., define exit().

@david-a-wheeler
Copy link
Contributor Author

One interesting aspect is that this recommends using -WError with specific values instead of "any warning". That has very different effects - turning all warnings into errors creates strong dependencies on specific compiler versions, but enumerating a few cases does not do the same thing. This would become something like (for GCC, I suspect clang is similar/identical):

-Werror=implicit-function-declaration -Werror=int-conversion
-Werror=incompatible-pointer-types
-std=gnu2x -Werror=old-style-definition

When not using autoconf (maybe we can create a workaround by declaring exit() and friends?):

-Werror=implicit-int

Maybe:

 -Werror=return-types

This needs more research. But expressly preventing dangerous constructs that often no longer work, and have been supported (or required) by C99, seems reasonable. 24 years is time enough to fix bad code :-).

@david-a-wheeler
Copy link
Contributor Author

I just checked clang 14.0.3; it accepts:

-Werror=implicit-function-declaration -Werror=int-conversion
-Werror=incompatible-pointer-types
-std=gnu2x -Werror=old-style-definition
-Werror=implicit-int

It does not accept -Werror=return-types

@david-a-wheeler
Copy link
Contributor Author

I contacted the autoconf developers. Looks like the latest version of autoconf will address some of these. It's planned to be released next week (December 2023). A discussion about this should soon show here: https://lists.gnu.org/archive/html/autoconf/2023-12/threads.html

david-a-wheeler added a commit that referenced this issue Jan 22, 2024
This adds some `-Werror` flags to help people switch to
Modern C instead of some problematic legacy constructs.

Signed-off-by: David A. Wheeler <dwheeler@dwheeler.com>
thomasnyman added a commit that referenced this issue Feb 28, 2024
This adds some `-Werror` flags to help people switch to
Modern C instead of some problematic legacy constructs.

Co-authored-by: Thomas Nyman <thomas.nyman@ericsson.com>
Signed-off-by: David A. Wheeler <dwheeler@dwheeler.com>
Signed-off-by: Thomas Nyman <thomas.nyman@ericsson.com>
thomasnyman added a commit that referenced this issue Feb 28, 2024
This adds some `-Werror` flags to help people switch to
Modern C instead of some problematic legacy constructs.

Co-authored-by: Thomas Nyman <thomas.nyman@ericsson.com>
Signed-off-by: David A. Wheeler <dwheeler@dwheeler.com>
Signed-off-by: Thomas Nyman <thomas.nyman@ericsson.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant