[MPlayer-dev-eng] Re: [PATCH] Re: min() and max() macro definitions

adland adland123 at yahoo.com
Sun Mar 20 07:56:21 CET 2005


link with more details about side effects
http://ou800doc.caldera.com/cgi-bin/info2html?(cpp.info)Macro%20Pitfalls〈=en

default definition
 #define MIN(X, Y)  ((X) < (Y) ? (X) : (Y))

Learned that this macro as defined by default is unsafe.
possible side effect which comes from using a function for arguments versus 
variables.

However there were no visible examples of this kind of usage in the current
 source code with a quick check.

there is a possible work around for GNU C compilers mentioned to avoid side
 effect

      #define MIN(X, Y)                     \
      ({ typeof (X) __x = (X), __y = (Y);   \
         (__x < __y) ? __x : __y; })

otherwise they say to make the programmers use temp variables storing 
the calculated value of function and not put function calls directly in the macro


is there another issue ?




More information about the MPlayer-dev-eng mailing list