-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Whenever BLE stack is used by the application, a global definition BLE
is added to the project, but the value of this define is not set explicitly. Due to that, the correct way to check if BLE is used by the app is to use #ifdef BLE
preprocessor directive, which checks if the respective macro is defined at all without paying any attention to the assigned value of this macro. However, in some portion of the code #if BLE
preprocessor directive is used. This is problematic because whenever you add a definition (either globally for the project or in a header file) without explicitly defining its value, it's up to the compiler to select the default one, and not all of the compilers assign a non-zero value. For example, GNU/GCC toolchain will assign the value of zero by default. Consider the following sample code:
#define MY_DEF_WITH_NO_EXPLICIT_VALUE /* This definition will set MY_DEF_WITH_NO_EXPLICIT_VALUE to 0 in GCC */
#define MY_DEF_WITH_EXPLICIT_VALUE (1)
#if MY_DEF_WITH_NO_EXPLICIT_VALUE
#warning "You will NOT see this warning in GCC because the value of MY_DEF_WITH_NO_EXPLICIT_VALUE is implicitly set to zero"
#endif /* MY_DEF_WITH_NO_EXPLICIT_VALUE */
#ifdef MY_DEF_WITH_NO_EXPLICIT_VALUE
#warning "You will see this warning even in GCC because MY_DEF_WITH_NO_EXPLICIT_VALUE is defined, its underlying value does not matter for ifdef directive"
#endif /* MY_DEF_WITH_NO_EXPLICIT_VALUE */
#if MY_DEF_WITH_EXPLICIT_VALUE
#warning "You will see this warning with any compiler because MY_DEF_WITH_EXPLICIT_VALUE is explicitly set to 1"
#endif /* MY_DEF_WITH_EXPLICIT_VALUE */
#ifdef MY_DEF_WITH_EXPLICIT_VALUE
#warning "You will see this warning with any compiler because MY_DEF_WITH_EXPLICIT_VALUE is defined, its underlying value does not matter for ifdef directive"
#endif /* MY_DEF_WITH_EXPLICIT_VALUE */
Some portions of the Link Layer and associated code wrongly use #if
directive instead of #ifdef
, leading to incorrect code pieces being selected by the preprocessor. Identified occurrences of the issue:
#if BLE #if BLE
Metadata
Metadata
Assignees
Labels
Type
Projects
Status