#include <stdio.h>
#define YY "Sample Text"
#define FINALDATA "START TEXT (" func2(func1(142),YY) ") END TEXT"
// #define FINALDATA func2(func1(142),YY) //this works fine
int func1(int data)
{
return data;
}
char* func2(int val, char* data)
{
return data;
}
int main()
{
printf("Final Data is %snn", FINALDATA);
return 0;
}
in the above C/C++ program, I need to concatenate two strings with return value of the function. But below is the error
main.cpp: In function ‘int main()’:
main.cpp:11:44: error: expected ‘)’ before ‘func2’
11 | #define FINALDATA "START TEXT (" func2(func1(142),YY) ") END TEXT"
| ^~~~~
main.cpp:25:36: note: in expansion of macro ‘FINALDATA’
25 | printf("Final Data is %snn", FINALDATA);
| ^~~~~~~~~
main.cpp:25:11: note: to match this ‘(’
25 | printf("Final Data is %snn", FINALDATA);
| ^
What might be wrong? isnt it possible to use MACRO this way to append the strings with a function call ?