OpenCyphal / libcanard

A compact implementation of the Cyphal/CAN protocol in C for high-integrity real-time embedded systems
http://opencyphal.org
MIT License
337 stars 195 forks source link

Introduce internal includes section to avoid potential implicit declaration warnings #219

Closed ycherniavskyi closed 11 months ago

ycherniavskyi commented 11 months ago

During the integration of the libcanard into a project based on ChibiOS 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':
<command-line>: 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".