Passing NULL to puts () and other functions: how to suppress the "null argument where non-null required" warning with an analogue if (NULL) puts (NULL);


There is a macro like this:

#define __ex_msg (__ex_idx && __ex_idx < TCM_MAX) ? \
                 __ex_msgs[__ex_idx-1] : (const char *)0

Accordingly, in this design:

if(__ex_msg) puts(__ex_msg);

We get a fair splash:

null argument where non-null required (argument 1) [-Wnonnull]

The only thing that comes to mind so far is to break it into 2 macros, something like this:

#define __ex_have_msg (__ex_idx && __ex_idx < TCM_MAX) ? \
                      __ex_msgs[__ex_idx-1] : (const char *)0
#define __ex_msg __ex_msgs[__ex_idx-1]

But for some reason I don't really like this. What else can you think of here, besides __ex_msg() into a function? Do not offer to disable warnings 🙂


puts() required


or you can transform define

#define __ex_msg  if( __ex_idx && __ex_idx < TCM_MAX) \
Scroll to Top