You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When trying to define a logging backend with LOG_BACKEND_DEFINE, I get errors relating to the macro expansion of LOG_BACKEND_DEFINE even though all of the arguments for the macro are correct.
To Reproduce
Create and compile a source file to create a logging backend as such
#include <logging/log_backend.h>// Include only this
... function declarations ...
static struct log_backend_api my_api = {
.put = put,
.put_sync_string = put_sync_string,
.put_sync_hexdump = put_sync_hexdump,
.dropped = dropped,
.panic = panic,
.init = init,
};
LOG_BACKEND_DEFINE(my_log, my_api, true);
Yields many errors and warnings upon compilation. It looks like the UTIL_CAT macro is not defined so the compiler thinks we're doing a function declaration.
Expected behavior
The LOG_BACKEND_DEFINE macro should compile and behave if all of its arguments are correct. log_backend.h should include the necessary headers (in this case, sys/util.h) for its implementation.
Impact
To fix I can include the missing sys/util.h header in log_backend.h so that UTIL_CAT is defined. Alternatively, I can include that same header in my logger backend source or include another log_*.h file which includes it like log_core.h.
Screenshots or console output
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:77:16: warning: parameter names (without types) in function declaration
static struct log_backend_control_block UTIL_CAT(backend_cb_, _name) = \
^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:77:16: error: function 'UTIL_CAT' is initialized like a variable
static struct log_backend_control_block UTIL_CAT(backend_cb_, _name) = \
^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:79:3: error: field name not in record or union initializer
.active = false, \
^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:79:3: note: (near initialization for 'UTIL_CAT')
.active = false, \
^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
^~~~~~~~~~~~~~~~~~
In file included from /mnt/c/Dev/ncs/zephyr/include/sys/atomic.h:12:0,
from /mnt/c/Dev/ncs/zephyr/include/logging/log_msg.h:9,
from /mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:9,
from /mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:1:
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:79:13: error: invalid initializer
.active = false, \
^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:79:13: note: (near initialization for 'UTIL_CAT')
.active = false, \
^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
^~~~~~~~~~~~~~~~~~
In file included from /mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:1:0:
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:80:3: error: field name not in record or union initializer
.id = 0, \
^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:80:3: note: (near initialization for 'UTIL_CAT')
.id = 0, \
^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:80:9: warning: excess elements in scalar initializer
.id = 0, \
^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:80:9: note: (near initialization for 'UTIL_CAT')
.id = 0, \
^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
^~~~~~~~~~~~~~~~~~
/mnt/c/Dev/ncs/zephyr/include/logging/log_backend.h:85:19: error: 'backend_cb_' undeclared here (not in a function); did you mean 'log_backend_get'?
.cb = &UTIL_CAT(backend_cb_, _name), \
^
/mnt/c/Dev/designblocksstandalone/applets/cloud/src/cloud_log_backend.c:46:1: note: in expansion of macro 'LOG_BACKEND_DEFINE'
LOG_BACKEND_DEFINE(cloud_log, cloud_api, true);
^~~~~~~~~~~~~~~~~~
```
The text was updated successfully, but these errors were encountered:
The UTIL_CAT macro which is used in log_backend.h is implemented in
sys/util.h.
Fixeszephyrproject-rtos#21045.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Describe the bug
When trying to define a logging backend with LOG_BACKEND_DEFINE, I get errors relating to the macro expansion of LOG_BACKEND_DEFINE even though all of the arguments for the macro are correct.
To Reproduce
Create and compile a source file to create a logging backend as such
Yields many errors and warnings upon compilation. It looks like the UTIL_CAT macro is not defined so the compiler thinks we're doing a function declaration.
Expected behavior
The LOG_BACKEND_DEFINE macro should compile and behave if all of its arguments are correct. log_backend.h should include the necessary headers (in this case, sys/util.h) for its implementation.
Impact
To fix I can include the missing sys/util.h header in log_backend.h so that UTIL_CAT is defined. Alternatively, I can include that same header in my logger backend source or include another log_*.h file which includes it like log_core.h.
Screenshots or console output
The text was updated successfully, but these errors were encountered: