I have a simple cpp file as following on Unix environment:
#include <stdio.h>
#ifndef HELLO
#define HELLO "hello"
#endif
int main()
{
printf("HELLO = %s \n", HELLO);
return 0;
}
If this was compiled and ran, it prints out HELLO = HELLO
.
However, when I do export HELLO="HELLO"
, then compile the program using g++ -Wall -g -DHELLO
, I get a warning saying:
warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘int’ [-Wformat=] printf("HELLO = %s \n", HELLO);
When I run the program, I get a segmentation fault.
How would I print -DHELLO
in the code?