www.gibmonks.com

Main Page




Previous Page
Next Page

[Page 1282 (continued)]

Answers to Self-Review Exercises

F.1

a) #. b) #elif, #else. c) #define. d) white space. e) #undef. f) #ifdef, #ifndef. g) Conditional compilation. h) assert. i) #include. j) ##. k) #. l) \.

F.2

(See below.)

 1  // exF_02.cpp
 2  // Self-Review Exercise F.2 solution.
 3  #include <iostream>
 4
 5  using std::cout;
 6  using std::endl;
 7
 8  int main()
 9  {
10     cout << "__LINE__ = " << __LINE__ << endl
11          << "__FILE__ = " << __FILE__ << endl
12          << "__DATE__ = " << __DATE__ << endl
13          << "__TIME__ = " << __TIME__ << endl
14          << "__cplusplus = " << __cplusplus << endl;
15
16     return 0;
17
18  }  // end main


[Page 1283]

 __LINE__ = 9
 __FILE__ = c:\cpp4e\ch19\ex19_02.CPP
 __DATE__ = Jul 17 2002
 __TIME__ = 09:55:58
 __cplusplus = 199711L


F.3
  1. #define YES 1

  2. #define NO 0

  3. #include "common.h"

  4.    #if defined(TRUE)
           #undef TRUE
           #define TRUE 1
       #endif
    

  5.    #ifdef TRUE
           #undef TRUE
           #define TRUE 1
       #endif
    

  6.    #if ACTIVE
           #define INACTIVE 0
       #else
           #define INACTIVE 1
       #endif
    

  7. #define CUBE_VOLUME( x ) ( ( x ) * ( x ) * ( x ) )


Previous Page
Next Page