__min macro

__min macro

Does the __min macro exist in icc ? I found min(), but it doesn't do the same thing since __min replace the expression with : and ?.


3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Good question. I think it's a Microsoft thing not an Intel thing? It's part of Fortran too. It could be defined as:

#define __min(X, Y) ((X) < (Y) ? (X) : (Y))

It's used by:


So the "Standard Library" has non standard functions that have one or more underscores like __min--it's best to stay away from anything with an underscore for portable standard code.

IMHO I never did like using the ? operator. I'd just make a nice readable if function but then you'd need one for each datatype like:

int min(int x, int y)


int min;

if (x < y)

min = x;


min = y;

return min;

} // end min

This is a long standing problem with plenty of portability pitfalls. If you're writing C++, std::min() ought to work portably and efficiently, unless your application brings serious violation of namespaces, or some non-standard macro gets in the way. If the std:: is written explicitly, it should work even when there is a min() defined in another namespace. In my recent experience, ICL doesn't have a conflicting min() macro, at least not in C++ mode.

Several major C compilers have extensions such as the one you mention which are intended to have advantages, offset by non-portability. I haven't seen any use of the one which comes with gcc, and don't know if it works with any or all Intel compilers.

The main problem with ? is the possibility of side effects when an expression is evaluated multiple times.

The major compilers are smart enough, in the absence of side effects, to generate efficient code according to the data types.

Leave a Comment

Please sign in to add a comment. Not a member? Join today