#define

This is a discussion on #define within the C Programming forums, part of the General Programming Boards category; Hi i have 4 expressions ( each of them have only one arithmetical operator (+,-,*,/) ) a>b?a+b:b+a a>b?a-b:b-a a>b?a*b:b*a a>b?a/b:b/a ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    71

    #define

    Hi

    i have 4 expressions ( each of them have only one arithmetical operator (+,-,*,/) )

    a>b?a+b:b+a
    a>b?a-b:b-a
    a>b?a*b:b*a
    a>b?a/b:b/a

    Is there any way to write a general macro for this ? something like EXPR(X) where we could substitute X with +,-,*,/ .. or any alternate way to do this ?

    Thanks

  2. #2
    Registered User
    Join Date
    Dec 2008
    Location
    Black River
    Posts
    128
    Code:
    #define EXPR(x, y, op)   ((x) > (y) ? (x) op (y) : (y) op (x))
    And then you call it:

    Code:
    var1 = EXPR(x, y, -);
    var2 = EXPR(x, y, /);
    ...

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    71

    thanks

    Thanks a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer within a Struct
    By Bladactania in forum C Programming
    Replies: 11
    Last Post: 04-03-2009, 10:20 PM
  2. Why?!?
    By p3rry in forum C Programming
    Replies: 3
    Last Post: 01-08-2009, 11:52 AM
  3. size of an integer pointer
    By onebrother in forum C Programming
    Replies: 5
    Last Post: 07-09-2008, 11:49 AM
  4. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 08:22 AM
  5. float toolbar!
    By c-- in forum Windows Programming
    Replies: 5
    Last Post: 02-04-2003, 08:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21