Hi, I need to have my compiler take preprocessor definitions from the
command line. How does it differ from normal command line parameter passing (main(int arc, char *argv[])) ?
Thanks.

Recommended Answers

All 5 Replies

It depends on the compiler; you'll usually see things like -D<symbol> or \D<symbol>. Look it up in your documentation.

Thanks for the tip. I'm using Dev-C++. And I got the preprocessor flag to work.
Thanks.

i need it fast

Hi, I need to have my compiler take preprocessor definitions from the
command line. How does it differ from normal command line parameter passing (main(int arc, char *argv[])) ?
Thanks.

commented: Digging up a thread from 3 years ago +0
commented: Rude -2

1. g++ -DHAVE_CONFIG -Wall -std=c++98 -o myprogram
2. ,/myprogram hello world

in 1., the command line args are used by the c preprocessor, some are forwarded to the compiler and linker

in 2., the command line args are passed to myprogram and are available as parameters passed to main

preprocessor directives/macros are processed at the time of compilation. Arguments relevant to preprocessor (e.g. -DXXX=value) are passed to compiler and used by compiler. Any argument passed on command line is called command line arguments. :). So these are the CLI args to compiler.
After compilation (and linking) the executable of your program is ready.. when you call/execute this executable with CLI args, these would go to main() and will be be available to your program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.