|
|
|
|
|
by Someone
4388 days ago
|
|
"min" is a pathological case for a macro because it isn't what macros were meant for. Tell that to Kernighan and Ritchie. The second macro in K&R (I googled a PDF of the second edition) is #define max(A, B) ((A) > (B) ? (A) : (B))
Yes, that's lowercase 'max', and they even mention "This macro will work for any data type; there is no need for different kinds of max for different data types, as there would be with functions"Macros certainly were intended for this, as it was the only way to guarantee that the compiler inlined code (probably the only way it ever inlined function calls) And for the curious: the first macro they give is #define forever for(;;)
That certainly is what macros were meant for :-), and doesn't even save on typing.But yes, in modern C, nobody would use a macro for this. |
|