Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ethomson
Copy link
Member

Make c standard configurable; defaulting to an extension-free c90

GravisZro and others added 4 commits October 18, 2024 22:26
This PR ensures and enforces C90 conformance for all files C, including tests.

* Modify CMakeLists.txt to mandate C90 conformance (for better compiler compatibility)
* Update deps/ntlmclient/utf8.h to latest version
* Modify two tests and one header to use C comments instead of C++ comments
Users can now set up cmake with -DC_STANDARD=... or -DC_EXTENSIONS=...
We default to C90 with C_EXTENSIONS=OFF, but callers can override if
they desire.
The memory sanitizer builds are special snowflakes; let them be c90 with
extensions.
@ethomson ethomson merged commit 3594a54 into main Oct 18, 2024
18 of 19 checks passed
@ethomson ethomson deleted the ethomson/c90-2 branch October 18, 2024 22:03
@ethomson ethomson added the build label Oct 18, 2024
Comment on lines +381 to +382
- `C_STANDARD`: the C standard to compile against; defaults to `C90`
- `C_EXTENSIONS`: whether compiler extensions are supported; defaults to `OFF`
Copy link

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

😔 Not knowing about it, mostly. Does this solve the problem in a superior way?

Copy link

Choose a reason for hiding this comment

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

Well, "standard" means it is already known and/or easy to discover.
It is referenced in the documentation of the target properties, for determining the default value.
It would nicely complement the use of other standard variables (CMAKE_C_FLAGS).

And the standard pattern to provide default values for an input variable is to use cache variables and options. This can be discovered by CMake GUIs.

set(CMAKE_C_STANDARD "90" CACHE STRING "The C standard to compile against")
option(CMAKE_C_EXTENSIONS "Whether compiler extensions are supported" "OFF")

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure I understand what you're saying, but does it actually work for us given that we have deps that may have a variety of other cstd compliance levels? In other words does it apply to the whole of the system?

With this PR, we apply the cstd level just to our projects. I guess we could use this standard feature as the default and then make the deps specify their compliance levels individually. Or, I suppose, just let them error.

Copy link

Choose a reason for hiding this comment

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

does it apply to the whole of the system?

Yes.

does it actually work for us given that we have deps that may have a variety of other cstd compliance levels?

I can't answer that. I arrived here from package manager which de-vendors deps, so they are isolated from this setting.

But the reason I did ask is similar, only the other way: libgit2 might also be used a subproject, inheriting top-level settings.

So no change requested.

FTR the vcpkg port carries a patch to set the standard to 99, with the comment "for 'inline' in system headers". The patch can go away with the new change. But 90 isn't the right standard when it comes to Android (#6574). Maybe what I really want is libgit2 to generally chose 99 for Android instead of requiring users to make that override.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that your advice is good, see #6914.

Do you think that we should default to 99 on Android? 🤔

Copy link

Choose a reason for hiding this comment

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

Why not?
At least this is the current patch in vcpkg, building in CI with NDK r26, API level 21.

Even if there were Android users with another toolchain: would they be hurt with the default being 99?

Copy link
Member Author

Choose a reason for hiding this comment

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

@dg0yt can you test #6914 ? I don't have an android environment to test on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants