CompuServe Thread

#Failure to incline

2 messages in this thread
#7132From: David SachsJul 18, 1993 10:14 PM
Symantec C++ fails to inline the "max" calls in the following example: #include <iostream.h> template <class T> inline T max(T a,T b) { return a>b?a:b; } template <class T> inline T min(T a,T b) { return a>b?b:a; } long max(long,long); // Necessary for argument covnversion for max(long,int) int main(int, char**) { long a = 1; long b = 2; int c = 3; cout << max(a,b) << "," << min(a,b) << "," << max(b,c) << endl; return 0; }
#7140From: John BaxterJul 19, 1993 2:54 AM
David, >> Symantec C++ fails to inline the "max" calls in the following example Hmmm…so it does. That is triggered by the declaration long max(long,long); // Necessary for argument covnversion for max(long,int) (which of course you need unless you elect to explicitly cast the int to a long). It would appear that, for this version, this is a "don't do that" situation. You could write your own max(long,int) [and, probably max(int, long)]. No actual extra code results, compared to a C++ which did inline the max's in the example. Even changing the declaration to read inline long max(long,long); // Necessary for argument covnversion for max(long,int) doesn't help. Not necessarily a bug, since the compiler isn't _required_ to inline _anything_. It's only a bug if Symantec intends this max to be inlined. –John