assert.h should not include non libc headers #41765
Labels
area: Minimal libc
Minimal C Standard Library
Enhancement
Changes/Updates/Additions to existing features
Describe the bug
If a source file includes the standard
assert.h
header, it also includes non standard Zephyr specific headers, as the assertions useprintk
, which includes logging.In my case, a HAL source file included
assert.h
, and ended up also including the following files (in order):And so a non Zephyr source file ended up "contaminated" with Zephyr definitions. One such definition was the
KHZ
macro, which conflicted with a definition of the same name in the HAL.Expected behavior
In my opinion, standard library headers should not rely on non standard headers, or at least should be extra careful about including such headers.
Impact
Definitions ending up in a source file not expecting them (HAL) can cause redefinition warnings, with a possibility of the wrong definitions being chosen.
Another possible case is a definition coincidentally having the same name as a symbol in a source file. If we're unlucky, the symbol would be quietly substituted, possibly causing a bug.
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: