help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

preprocessor defs on the command line


From: Chris
Subject: preprocessor defs on the command line
Date: 15 Jan 2006 14:31:21 -0800
User-agent: G2/0.2

I'm learning C++ from Thinking in C++ by Eckel.  I'm trying to solve an
exercise problem.  Here is the first part:

Write a program with conditionally-compiled code in main( ), so that
when a preprocessor value is defined one message is printed, but when
it is not defined another message is printed. Compile this code
experimenting with a #define within the program.

My solution:

#include <iostream>
using std::cout;
using std::endl;

int main() {
        //#define PI 3.14159

        #ifdef PI
                cout << "PI is defined." << endl;
        #endif

        #ifndef PI
                cout << "PI is not defined." << endl;
        #endif

}

Then:
Then discover the way your compiler takes preprocessor definitions on
the command line and experiment with that.

How can I create preprocessor definitions on the command line?  I was
look at the man pages, but all I found was an option for macros.  Are
there docs for g++ that are easier to use than the man pages?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]