Closed adolfogc closed 5 years ago
I recall someone in the past brought up a similar suggestion for libuavcan, saying that it would be nice to have a config header for preprocessor overrides. We ended up not changing anything because one can always override things via the compiler's command line; e.g. -DCANARD_ASSERT=assert
for Clang or GCC. Does that not work for you?
Hi Pavel,
Thanks for your reply.
Does that not work for you?
The problem is that I need to use another macro, Q_ASSERT, which is defined as below:
#define Q_ASSERT(test_) ((test_) \
? (void)0 : Q_onAssert(&Q_this_module_[0], (int_t)__LINE__))
Source: https://github.com/QuantumLeaps/qpc/blob/master/include/qassert.h#L142
As far as I know, using -DCANARD_ASSERT=Q_ASSERT
wouldn't work because another header file, that in which Q_ASSERT
is defined, would still need to be included in canard.h
.
Indeed. You could instruct the compiler to pre-include a specific file, but that would probably be suboptimal. Seems like we need a config header, not just for assertions, but for all compile-time options (of which there are currently only assertions, but this may change in the future). canard_build_config.h
should work, I suppose? Any objections? @adolfogc would you be able to implement that?
@pavel-kirienko Sounds good. I've implemented those changes in #72. Please review them.
Hello,
I need to override the
CANARD_ASSERT
macro in a project in which I included Libcanard as a Git submodule. I don't want to make a separate copy ofcanard.h
just to override this macro. A convenient solution to this problem is to have a separatecanard_assert.h
header for the user to provide alternative macro definitions. This header would be included bycanard.h
. A default implementation would be provided, and the user could use a custom one if he/she wished to provide an alternative definition of the macros.What do you think?
Best regards, Adolfo