This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Defining and undefining #defines from command line


Hi,
I'm the simple program:

#include<stdio.h>
#define AGE 29
int main(){
??? printf("Hello, I'm %d years old\n",AGE);
??? return 0;
}

I compile it: gcc hello.c -o hello and the result is: Hello, I'm 29 years old.
But if I try to define from gcc instantiation other AGE value as: gcc
-UAGE -DAGE=30 hello.c -o hello. In this case appears the warning:

hello.c:2:1: warning: "AGE" redefined
<command-line>: warning: this is the location of the previous definition

If I use gcc -DAGE=30 -UAGE hello.c -o hello no warnings appears, but
the result is: Hello, I'm 29 years old.

In gcc manual says: "-D and -U options are processed in the order they
are given on the command line"

Anybody knows the correct way for change any defined constant or macro
in the code. I'm using gcc 4.3.4 in Debian

Thanks

--
*****************************************
José Luis García Pallero
jgpallero@gmail.com
(o<
/ / \
V_/_
Use Debian GNU/Linux and enjoy!
*****************************************


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]