Thread: Min and Max Macros

  1. #1
    Batman.......hehehehe
    Guest

    Min and Max Macros

    Hey I would like to know what are the min and max macros....

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    min and max macro's compare two values and return either the smaller or larger value respectively. It compares numerical data types either signed or unsigned. The prototypes look like this.

    #define min(a, b) (((a) < (b)) ? (a) : (b))
    #define max(a, b) (((a) > (b)) ? (a) : (b))

    The macro's are defined in the windows header file.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    106
    you can use a inline function it is easier like below code

    #inline min(int a,int b){ a<b ? a : b ;}

    and the max one is same
    C++ Makes you Feel Better

    "Gravity connot be held reponsible for people falling in love"--Albert Einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help finding the max and min of a 2d array
    By finalreign in forum C Programming
    Replies: 6
    Last Post: 04-29-2009, 11:39 AM
  2. Max Min Problem
    By smithc2005 in forum C Programming
    Replies: 7
    Last Post: 10-22-2008, 10:38 AM
  3. Ranged numbers
    By Desolation in forum Game Programming
    Replies: 8
    Last Post: 07-25-2006, 10:02 PM
  4. Variable Min and Max Program
    By EdanD in forum C Programming
    Replies: 8
    Last Post: 06-30-2004, 07:48 PM
  5. Double output!
    By Spurnout in forum C++ Programming
    Replies: 3
    Last Post: 11-02-2002, 03:35 AM