Day: June 14, 2020

How to print the value of a #define variable during compilation

This is a nice trick to see the value of a variable:

#define XSTR(x) STR(x)
#define STR(x) #x

#pragma message "The value of NETLIB_SOCK_TYPE: " XSTR(NETLIB_SOCK_FAMILY)

It is also a good idea to put an #error “See above” to stop the compilation after it print the value.

You show see something like this:

CC:  nsh_netcmds.c
In file included from nsh_netcmds.c:93:
.../apps/include/netutils/netlib.h:132:9: note: #pragma message: The value of NETLIB_SOCK_TYPE: 2