コードのコンパイル時に特定の値を変数に代入したい (C および C++ の場合):
たとえば、次のようになります。
//test.c
int main()
{
int x = MYTRICK ; (edit: changed __MYTRICK__ to MYTRICK to follow advices in comment)
printf ("%d\n", x);
return 0;
}
次のようなことができます:
gcc -XXX MYTRICK=44 test.c -o test
そして結果として:
$./test
44