POV-Ray : Newsgroups : povray.general : pov source gcc3 problem : Re: pov source gcc3 problem Server Time
6 Aug 2024 02:25:18 EDT (-0400)
  Re: pov source gcc3 problem  
From: Warp
Date: 3 Aug 2002 06:25:57
Message: <3d4bafb5@news.povray.org>
Christoph Hormann <chr### [at] gmxde> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.