When this feature is unavailable, #cmakedefine leaves its macro undefined, triggering -Wundef. I noticed this while building the kernel for iOs.
Use #cmakedefine01 to always generate 0 or 1.
When this feature is unavailable, #cmakedefine leaves its macro undefined, triggering -Wundef. I noticed this while building the kernel for iOs.
Use #cmakedefine01 to always generate 0 or 1.
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--006a51241073e994b41acfe9ec718e94-->
<!--021abf342d371248e50ceaed478a90ca-->
See the guideline and AI policy for information on the review process. A summary of reviews will appear here.
<!--5faf32d7da4f0f540f40219e4f7537a3-->
I haven't observed HAVE_FDATASYNC myself, but applied the same change anyway.
Please don't make random changes for no reason.
Maybe simply revert 976b034b13d28877aee641833d5ee28a8cc5d83f?
When this feature is unavailable, #cmakedefine leaves its macro
undefined, triggering -Wundef. Use #cmakedefine01 to always generate 0
or 1.
The change seems fine to me, but it would be nice to be consistent across these definitions.
using
#if defined(HAVE_SYSTEM)looks ugly imo...
Is this concern aesthetic or technical?
However, I agree that using #if defined(...) poses a problem. We can't spot a typo in the macro name, for example #if defined(HAVE_SUSTEM). Also see #36874.
... but it also risks someone using
#if HAVE_SYSTEMaccidentally.
In this case, it does not change behavior when bitcoin-build-config.h contains #define HAVE_SYSTEM 1. And it will trigger -Wundef when the macro is undefined.
The problem of detecting misused directives in the source code remains for #cmakedefine01 as well. Perhaps this is a task for the linter.
Can we not use a single style...
... it would be nice to be consistent across these definitions.
The current usage is not uniform either. For example, here are the different patterns for configuration macro definitions:
#define HAVE_FOO or undefined -- is not used.#define HAVE_FOO 1 or undefined:$ git grep '#cmakedefine ' -- cmake/bitcoin-build-config.h.in | wc -l
18
#define HAVE_FOO 1 or #define HAVE_FOO 0:$ git grep '#cmakedefine01' -- cmake/bitcoin-build-config.h.in | wc -l
4
Use
#cmakedefine01to always generate 0 or 1.
This approach gives us free protection against a misspelled macro name, which will trigger the -Wundef compiler warning.
Here are some useful external resources:
Bottom line: I agree with this PR change. I'd really like to see here a new linter check that prevents accidental misuse of #ifdef, #ifndef or defined() for configuration macros set via #cmakedefine01.