I`m trying to compile the following program
#include <stdio.h>
#define __stringify_1(x...) #x
#define __stringify(x...) __stringify_1(x)
#define FOO(expression)\
printf("prefix" __stringify(expression))
int main(int argc, char **argv)
{
FOO(10 % 4); // <-- This is a problematic one
FOO(10 == 4);
}
This yeilds a warning on compilation: warning: conversion lacks type at end of format [-Wformat=]
The reason for this warning is that expression is actually expaneded to printf("prefix" "10 % 4"), hence compiler expects a "formatter". Is there any solution to pass such expressions to macro without getting a warning ?
Thanks
Use
printf("prefix%s", __stringify(expression))to disable the formatting impact ofexpression.