min, max, abs.. are macroses?

The real problem with the macros isn't that they are macros but that they are too simplistic.
gcc provides a way to declare and use locals as well as extract the data types of
the arguments to declare the locals inside the macros.

This only works for gcc as it is a gcc extension.
Does anybody use anything else... :slight_smile:

But it provides a very simple way to create macros that work properly and
will work for both C and C++

So for example this is better definition of max() that is still a macro:

#define max(a,b) \
       ({ typeof (a) _a = (a); \
           typeof (b) _b = (b); \
         _a > _b ? _a : _b; })

And a few others:

#define min(a,b) \
       ({ typeof (a) _a = (a); \
           typeof (b) _b = (b); \
         _a < _b ? _a : _b; })
#define abs(x) \
       ({ typeof (x) _x = (x); \
          _x > 0 ? _x : -_x; })

Although I would probabaly want to take a closer look at abs() to see if it is better to use >= vs >
i.e. does -0 create some problems?

etc...
So this could also easy be used for constrain() and round()

For my C entrenched brain it seems a whole lot easier than all the
template and class foo.

--- bill