-
Notifications
You must be signed in to change notification settings - Fork 2.1k
core/assert: reduce use of preprocessor #16375
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
Conversation
This changes the semantics for expressions in assert that do have side effects, as the side effects will still trigger with NDEBUG. However, I think the new behavior is actually convenient in many cases. I will call it A use case for |
In a follow up all instances of void foo(int bar)
{
(void)bar;
assert(bar == 42);
} can be converted to void foo(int bar)
{
assert_ng(bar == 42);
} And all instances of void foo(void)
{
int retval = bar_init();
(void)retval;
assert(retval == 0);
} can be converted to void foo(void)
{
assert_ng(bar_init() == 0);
} |
What does |
I'm also skeptical. |
Well, this is my selling point for it ;-) Because our CI always compiles without What is the point in having a program showing different observable behavior in absence of failed assertions with and without
But this provides a second macro with fixed semantics. It is not changing the semantics of |
Don't we have |
|
doesn't cppcheck warn on that? Anyhow, I'd rather fix those than use |
With --enable=style it indeed does. Maybe we should consider to just add I will drop |
Implement a large chunk of the previous preprocessor magic used to implement `assert()` as static inline C function instead. This function is used to implement the `assert()` macro. As result, the C compiler has more optimization opportunities. With GCC 10.2.0, this results in a slight reduction of ROM.
PR stripped of |
Strange. Using my toolchain I get 460 B less for |
Can you please provide a reason why this was closed? It is not really obvious from the course of discussion here. |
Contribution description
Implement a large chunk of the previous preprocessor magic used to
implement
assert()
as static inline C function instead. This functionis used to implement the
assert()
macro. As result, the C compilerhas more optimization opportunities. With GCC 10.2.0, this results
in a slight reduction of ROM.
Testing procedure
A test application was added in
tests/core_assert
that testsassert()
for correct behavior with bothNDEBUG
defined and without.Issues/PRs references
None