Mail Archives: djgpp/2002/04/03/06:30:29.1
Francesco Moi <francescomoi AT europe DOT com> wrote:
> Within it, it appears:
> short number=min(100,anothernumber);
> And I get this error message:
> implicit declaration of function `int min(...)'
Then that code is either unportable, or plain and simply buggy.
> Does anybody have any experience about including 'min' function?
Yes. The experience is that just about no C platform provides a
prebuilt 'min' function, so the above code would not compiler there.
That's mainly because you would need not just one, but rather a whole
slew of such functions, since you may want to take the minimum of a
pair of expressions in a wide range of types, from unsigned char to
long double.
Most C programmers would use a MIN macro, instead:
#define MIN(a,b) ((a)<(b) ? (a) : (b))
This has its own problems, but it has the benefit that you need only
this one, and it works for all numeric types.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -