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

Source: https://stackoverflow.com/questions/1562074/how-do-i-show-the-value-of-a-define-at-compile-time

2 thoughts on “How to print the value of a #define variable during compilation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s