Reputation: 363
I have following C program:
test.c
#include <stdio.h>
#define DEF0(v) #v
#define DEF(v) DEF0(v)
int main()
{
printf("RUNNING... %s\n", DEF(VAR));
}
Compilation
gcc -DVAR=-linux test.c
Running
./a.out
Gives
RUNNING... -1
Asm output
.file "test.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "-1"
.LC1:
.string "RUNNING... %s\n"
.text
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
movl $.LC0, %esi
movl $.LC1, %edi
xorl %eax, %eax
jmp printf
.cfi_endproc
.LFE11:
.size main, .-main
.ident "GCC: (GNU) 4.4.7 20120313 (Red Hat 4.4.7-4)"
.section .note.GNU-stack,"",@progbits
-linu
or -linuxx
does not cause such problem, but -linux/
does. Surrounding with quotes -DVAR="-linux"
does not help.
Problem is also visible on gcc 6 and 7. On cygwin everythings works FINE. I wonder if it is a bug or I do something wrong.
Upvotes: 2
Views: 67
Reputation: 18410
You can inhibit the definition of system- or gcc-specific macros by using -undef
, when compiling your object file:
gcc -undef -c -DVAR=-linux test.c
gcc test.o -o test
Then your macros should work as you expect. Note however, that you cannot use any of these predefined macros then, you should probably only use it on those object files you absolutely have to.
Upvotes: 2