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

allow code to build with -std=gnu23 (which is the new default in gcc-15) #2094

Merged
merged 8 commits into from
Dec 18, 2024

Conversation

fabiangreffrath
Copy link
Owner

No description provided.

@rfomin
Copy link
Collaborator

rfomin commented Dec 18, 2024

-std=gnu23 (for C23 with GNU extensions).

C23 is only partially implemented in Clang: https://clang.llvm.org/c_status.html#c2x
I think C99 is just fine for us.

@fabiangreffrath
Copy link
Owner Author

Linux GCC and MSYS2 pass without changes. Good.

@rfomin
Copy link
Collaborator

rfomin commented Dec 18, 2024

Linux GCC and MSYS2 pass without changes. Good.

Should we set the standard there?

set(CMAKE_C_STANDARD 99)

I think otherwise CMake will force C99 anyway.

@fabiangreffrath
Copy link
Owner Author

Indeed, seems that it overrides the standard at this point. I misread this as an "at least" requirement.

@fabiangreffrath
Copy link
Owner Author

I'll try this as an experiment.

@fabiangreffrath
Copy link
Owner Author

Linux GCC and MSYS2 pass without changes. Good.

Now that's the kind of trouble I was expecting. 😁

@fabiangreffrath fabiangreffrath marked this pull request as ready for review December 18, 2024 14:54
@fabiangreffrath
Copy link
Owner Author

Now, I consider these changes worth keeping. Is there anything we put to risk by including <stdbool.h> instead of defining our own false/true?

@fabiangreffrath fabiangreffrath changed the title attempt to build with -std=gnu23, which is the new default in gcc-15 allow code to build with -std=gnu23, which is the new default in gcc-15 Dec 18, 2024
@fabiangreffrath fabiangreffrath changed the title allow code to build with -std=gnu23, which is the new default in gcc-15 allow code to build with -std=gnu23 (which is the new default in gcc-15) Dec 18, 2024
@rfomin
Copy link
Collaborator

rfomin commented Dec 18, 2024

Is there anything we put to risk by including <stdbool.h> instead of defining our own false/true?

It should work, but I prefer to avoid it. It's misleading since we have our own boolean type with int32_t size.

@fabiangreffrath
Copy link
Owner Author

It should work, but I prefer to avoid it. It's misleading since we have our own boolean type with int32_t size.

Right, we don't let stdbool.h define our boolean type, just false and true. We still have typedef int boolean a few lines later.

@rfomin
Copy link
Collaborator

rfomin commented Dec 18, 2024

Right, we don't let stdbool.h define our boolean type, just false and true. We still have typedef int boolean a few lines later.

So why do we need stdbool.h? Because of https://en.cppreference.com/w/c/language/bool_constant?

@fabiangreffrath
Copy link
Owner Author

Because in newer C standards, true and false are reserved key words. You can check for them being defined, though, and we do so by checking the __bool_true_false_are_defined macro. But guess what, this macro is only ever defined if you include stdbool.h and this in turn unconditionally defines the key words.

Copy link
Collaborator

@rfomin rfomin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@fabiangreffrath
Copy link
Owner Author

Because in newer C standards, true and false are reserved key words. You can check for them being defined, though, and we do so by checking the __bool_true_false_are_defined macro. But guess what, this macro is only ever defined if you include stdbool.h and this in turn unconditionally defines the key words.

In other words, Schroedinger's cat. You only know if the key words are defined if you make sure they are defined. 😉

@fabiangreffrath
Copy link
Owner Author

LGTM.

Thanks!

@fabiangreffrath fabiangreffrath merged commit b53ee54 into master Dec 18, 2024
8 checks passed
@fabiangreffrath fabiangreffrath deleted the std_gnu23 branch December 31, 2024 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants