Amazon.com Widgets 12-3 Simple way
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 24, 2013, 09:42:16 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Answers to Exercises
| | |-+  Chapter 12
| | | |-+  12-3 Simple way
Pages: [1]   Go Down
Print
Author Topic: 12-3 Simple way  (Read 1720 times)
tadej5553
Full Member
***
Posts: 145


Email




« on: May 20, 2010, 12:41:29 PM »

main.m
Code: (Objective-C)
#import <Foundation/Foundation.h> 

#define MAX3(a,b,c) (((a) > (b)) ? (((a) > (c)) ? (a) : (c)) : (((b) > (c)) ? (b) : (c)))

int main (int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   
    NSLog(@"Maximum value of 6, 5 and -7 is: %i", MAX3(6, 5, -7));
   
    [pool drain];
    return 0;
}
Logged
rapididy
Newbie
*
Posts: 2






« Reply #1 on: February 24, 2011, 04:12:51 PM »

a better/shorter way?? Since we already have MAX defined:

#define MAX(a,b) ( ((a) > (b)) ? (a):(b) )
#define MAX3(x,y,z) ( (MAX(x,y)) > (z) ? (MAX(x,y)):(z) )
Logged
skochan
Administrator
Hero Member
*****
Posts: 3106







« Reply #2 on: February 26, 2011, 03:21:57 PM »

Or this:

Code: (Objective-C)
#define MAX(x,y,z)  MAX(MAX(x,y), z)

Cheers,

Steve
« Last Edit: February 26, 2011, 08:29:52 PM by skochan » Logged
piersb
Newbie
*
Posts: 2


Email




« Reply #3 on: October 03, 2011, 09:43:35 AM »

Oh, that's sneaky. I like.
Logged
Trimakas
Newbie
*
Posts: 9






« Reply #4 on: November 22, 2011, 08:01:27 AM »

Man.. I aspire to that!!

Todd
Logged
baptzmoffire
Newbie
*
Posts: 1


Email




« Reply #5 on: March 07, 2012, 03:29:05 PM »

Whoa...you're really blowin' my mind, right now, Steve.   Shocked
Logged
eagle74
Newbie
*
Posts: 24


www.cucinareblog.it


WWW Email




« Reply #6 on: May 31, 2012, 11:47:45 PM »

Whoa...you're really blowin' my mind, right now, Steve.   Shocked

It's true!!  Wink
Logged

"The more i know people the more i love dogs."Socrate
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.