home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK4 / SAMPLES / CPPTUTOR / INLINE.CP$ / INLINE
Encoding:
Text File  |  1991-12-12  |  669 b   |  30 lines

  1. // INLINE.CPP
  2.  
  3. // This is an example program from Chapter 2 of the C++ Tutorial. This
  4. //     program demonstrates the difference between a macro and an inline
  5. //     function.
  6.  
  7. #include <iostream.h>
  8.  
  9. #define MAX( A, B ) ((A) > (B) ? (A) : (B))
  10.  
  11. inline int max( int a, int b )
  12. {
  13.     if ( a > b ) return a;
  14.     return b;
  15. }
  16.  
  17. void main()
  18. {
  19.    int i, x, y;
  20.  
  21.    x = 23; y = 45;
  22.    i = MAX( x++, y++ );  // Side-effect:
  23.                          //     larger value incremented twice
  24.    cout << "x = " << x << " y = " << y << '\n';
  25.  
  26.    x = 23; y = 45;
  27.    i = max( x++, y++ );  // Works as expected
  28.    cout << "x = " << x << " y = " << y << '\n';
  29. }
  30.