#include <stdio.h>
#ifndef TEXT
#define TEXT "Text"
#endif
int main()
{
char text[] = { " " TEXT };
printf("%s\n", text);
return 0;
}
alex@alex:~/Проекты/test/macrotest$ gcc ./macrotest.c
alex@alex:~/Проекты/test/macrotest$ ./a.out
Text
alex@alex:~/Проекты/test/macrotest$ gcc ./macrotest.c -DTEXT="dsdd"
./macrotest.c: In function ‘main’:
<command-line>:0:6: error: expected ‘}’ before ‘dsdd’
./macrotest.c:9:25: note: in expansion of macro ‘TEXT’
char text[] = { " " TEXT };
^
alex@alex:~/Проекты/test/macrotest$ gcc ./macrotest.c -DTEXT=dsdd
./macrotest.c: In function ‘main’:
<command-line>:0:6: error: expected ‘}’ before ‘dsdd’
./macrotest.c:9:25: note: in expansion of macro ‘TEXT’
char text[] = { " " TEXT };
Што происходит? Почему? Как?