|
![](/i/fill.gif) |
Christoph Hormann <chr### [at] gmx de> wrote:
> Well, i'm no expert in c, but i guess
> max(++x, y)
> would cause problems.
Yes, that's the big problem.
Another minor problem is caused by the exact same reason: If you have
complicated statements as parameters to that "function", they will be
evaluated twice, thus producing inefficient code.
If you want to make the min() and max() functions in C++, the correct
way is to use templates. The result will be the same, but without the
mentioned problems (yes, compilers do a very good job when inlining this
type of functions and all temporary local variables will simply be gone).
template<typename T>
inline T max(const T& a, const T& b)
{
return a > b ? a : b;
}
(This is most probably how it's implemented in the STL, although there
*might* be some optimization as well...)
--
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}// - Warp -
Post a reply to this message
|
![](/i/fill.gif) |