X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fstr%2Fstr.h;h=70fe26c74fad3905b3acf2efd8ac0b792ba766a5;hp=f633bc757e1c15655b7a06cfcd21a08922bb4e2a;hb=90e94990efbd7fb280f5ff30d2da4401d7ce27fc;hpb=56cfebd643ca686a480e9395100ad2ad2eaf93fb diff --git a/ccan/str/str.h b/ccan/str/str.h index f633bc75..70fe26c7 100644 --- a/ccan/str/str.h +++ b/ccan/str/str.h @@ -43,4 +43,16 @@ static inline bool strends(const char *str, const char *postfix) return streq(str + strlen(str) - strlen(postfix), postfix); } + +/** + * stringify - Turn expression into a string literal + * @expr: any C expression + * + * Example: + * #define PRINT_COND_IF_FALSE(cond) \ + * ((cond) || printf("%s is false!", stringify(cond))) + */ +#define stringify(expr) stringify_1(expr) +/* Double-indirection required to stringify expansions */ +#define stringify_1(expr) #expr #endif /* CCAN_STR_H */