From 1c4da0d8202ab89743a5105bb58040a73fa7225c Mon Sep 17 00:00:00 2001 From: Yurii Cherniavskyi Date: Tue, 26 Dec 2023 11:27:35 +0200 Subject: [PATCH] Introduce internal includes section to avoid potential implicit declaration warnings (#219) During the integration of the `libcanard` into a project based on [ChibiOS](https://www.chibios.org) I want to change `CANARD_ASSERT` from the default `assert` to ChibiOS `osalDbgCheck`. It is done with the next C defines `-DCANARD_ASSERT=osalDbgCheck -DCANARD_CONFIG_HEADER=\"${BINDINGS_DIR}/canard/canard_config.h\"`, there to prevent implicit declaration warnings I unutilized `CANARD_CONFIG_HEADER` by providing a `canard_config.h` file with the following content: ``` #include "osal.h" ``` But because of `#include "_canard_cavl.h"` and `# include CANARD_CONFIG_HEADER` order in `canard.c` I still get implicit declaration warnings: ``` Compiling canard.c ../../ext/OpenCyphal/libcanard/libcanard/_canard_cavl.h: In function 'cavlPrivateRotate': : warning: implicit declaration of function 'osalDbgCheck' [-Wimplicit-function-declaration] ../../ext/OpenCyphal/libcanard/libcanard/_canard_cavl.h:30:25: note: in expansion of macro 'CANARD_ASSERT' 30 | # define CAVL_ASSERT CANARD_ASSERT | ^~~~~~~~~~~~~ ../../ext/OpenCyphal/libcanard/libcanard/_canard_cavl.h:98:5: note: in expansion of macro 'CAVL_ASSERT' 98 | CAVL_ASSERT((x != NULL) && (x->lr[!r] != NULL) && ((x->bf >= -1) && (x->bf <= +1))); | ^~~~~~~~~~~ ``` To resolve this issue `# include CANARD_CONFIG_HEADER` must be placed before `#include "_canard_cavl.h"`. --- README.md | 5 +++++ libcanard/canard.c | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ebc819..f651750 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,11 @@ If you find the examples to be unclear or incorrect, please, open a ticket. - Refactor the transfer reassembly state machine to enhance its maintainability and robustness. +#### v3.1.2 + +- Allow redefinition of CANARD_ASSERT via the config header; + see [#219](https://github.com/OpenCyphal/libcanard/pull/219). + ### v3.0 - Update branding as [UAVCAN v1 is renamed to Cyphal](https://forum.opencyphal.org/t/uavcan-v1-is-now-cyphal/1622). diff --git a/libcanard/canard.c b/libcanard/canard.c index d4577bf..863de50 100644 --- a/libcanard/canard.c +++ b/libcanard/canard.c @@ -3,7 +3,6 @@ /// Author: Pavel Kirienko #include "canard.h" -#include "_canard_cavl.h" #include // --------------------------------------------- BUILD CONFIGURATION --------------------------------------------- @@ -38,6 +37,11 @@ # error "Unsupported language: ISO C99 or a newer version is required." #endif +// --------------------------------------------- INTERNAL INCLUDES ---------------------------------------------- +// The internal includes are placed here after the config header is included and CANARD_ASSERT is defined. + +#include "_canard_cavl.h" + // --------------------------------------------- COMMON DEFINITIONS --------------------------------------------- #define BITS_PER_BYTE 8U