Advertisement
applehelpwriter

how to use #define macro

Sep 22nd, 2013
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Sept 22 2013
  2. //transform.xcodeproj
  3. //OS X 10.6.8
  4. //Xcode 4.2, Build 4C199
  5.  
  6. //example of using a define and a define with MACRO argument
  7.  
  8. #import <Foundation/Foundation.h>
  9.  
  10. //this is a straigthforward text substitution:
  11. #define TRANSITION "Therefore"
  12. //this one takes an argument to test if one number is smaller than another
  13. //and to return the smallest - see how its employed in the first printf statement below
  14. #define MINY(a,b) ((a)<(b)) ? (a) : (b)
  15.  
  16.  
  17. int main (int argc, const char * argv[])
  18. {
  19.    
  20.     @autoreleasepool {
  21.         int her = 31;
  22.         int you = (3*1)+her;
  23.         int me = 3*(1+her);
  24.        
  25.         //here's the macro employed to print the numbers
  26.         printf("\n%i %s %i", MINY(me, you), ((!(me == you)) ? "is smaller than" : "equals"), (((MINY(me, you)) == me) ? you : me));
  27.        
  28.         //now we use another conditional to identify which value belonged to which variable
  29.         if (me < you)
  30.             //and here's the other #define statement:
  31.             printf("\n%s, me is smaller than you.", TRANSITION);
  32.         else if (me > you)
  33.             printf("\n%s, you is smaller than me.", TRANSITION);
  34.         else
  35.             printf("\n%s, you and me are equal.", TRANSITION);
  36.        
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement