Re: Use of "min" and "max" functions
Re: Use of "min" and "max" functions
- Subject: Re: Use of "min" and "max" functions
- From: Andrew Farmer <email@hidden>
- Date: Fri, 18 May 2007 16:01:40 -0700
On 18 May 07, at 15:43, John Draper wrote:
I'm trying to use the "min" and "max" functions. These just return
the smallest or
largest value of the two passed aguments.
I'm getting a link error when I try and use "min(val1, val2)" and
get a ZeroLink
error on _min and _max.
Those functions don't exist in that form. There are fmin/fminl/fminf,
which operate on doubles, long doubles, and floating-point values,
respectively. If you need one that operates on integers, though,
you'll have to define it yourself.
The best possible definition for integers is probably (in a header
file):
inline extern min(int a, int b) __attribute__((always_inline));
inline extern min(a, b) { return a < b ? a : b; }
inline extern max(int a, int b) __attribute__((always_inline));
inline extern max(a, b) { return a > b ? a : b; }
(The always_inline attribute causes the functions to always be
inlined regardless of the optimization mode, obviating the need for a
non-extern definition somewhere in the program. Found this in the GCC
manual, section 5.36 "An Inline Function is As Fast As a Macro".)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden