Topic: Please compile this code
Author: hopps@mmm.com (Kevin J. Hopps)
Date: 18 Apr 1994 20:49:04 GMT Raw View
Chris Smith (chris.smith@ftl.mese.com) wrote:
> In article <lincmadCo34Ko.Cp2@netcom.com>
> lincmad@netcom.com (Linc Madison) writes:
> LM>I have tested the code below on Symantec C++ 6.0.1 for Macintosh and on
> LM>g++ 2.5.8 on SunOS, and both compilers violate the ARM requirements. I
> LM>would like to know how other compilers handle this particular situation,
> LM>since I believe in this instance it is the standard that is wrong and
> LM>these two compilers that are closer to the mark.
> LM>//----------------
> LM>#include <iostream.h>
> LM>void foo(short s) { cout << "short " << s << endl; }
> LM>void foo(int n) { cout << "int " << n << endl; }
> LM>void bar(short s) { cout << "short " << s << endl; }
> LM>void bar(long double ld) { cout << "l-dbl " << ld << endl; }
> LM>void rab(long li) { cout << "long " << li << endl; }
> LM>void rab(float f) { cout << "float " << f << endl; }
> LM>main()
> LM>{
> LM>char c = 22;
> LM>foo(c); // Symantec flags ambiguous, g++ calls foo(short)
> LM>// ARM 13.2 requires foo(int)
> LM>double d = 26.7;
> LM>bar(d); // both Symantec and g++ call bar(long double)
> LM>// ARM 13.2 requires "ambiguous"
> LM>char a = 28;
> LM>int n = 29;
> LM>rab(a); // both Symantec and g++ call rab(long) in both cases
> LM>rab(n); // ARM 13.2 requires "ambiguous" in both cases.
> LM>return 1;
> LM>}
> LM>//-------------
The SPARCompiler C++ 4.0 reports ambiguous in the required cases and
calls foo(int) in the first case.
Author: chris.smith@ftl.mese.com (Chris Smith)
Date: 15 Apr 94 08:11:00 GMT Raw View
In article <lincmadCo34Ko.Cp2@netcom.com>
lincmad@netcom.com (Linc Madison) writes:
LM>I have tested the code below on Symantec C++ 6.0.1 for Macintosh and on
LM>g++ 2.5.8 on SunOS, and both compilers violate the ARM requirements. I
LM>would like to know how other compilers handle this particular situation,
LM>since I believe in this instance it is the standard that is wrong and
LM>these two compilers that are closer to the mark.
LM>//----------------
LM>#include <iostream.h>
LM>void foo(short s) { cout << "short " << s << endl; }
LM>void foo(int n) { cout << "int " << n << endl; }
LM>void bar(short s) { cout << "short " << s << endl; }
LM>void bar(long double ld) { cout << "l-dbl " << ld << endl; }
LM>void rab(long li) { cout << "long " << li << endl; }
LM>void rab(float f) { cout << "float " << f << endl; }
LM>main()
LM>{
LM>char c = 22;
LM>foo(c); // Symantec flags ambiguous, g++ calls foo(short)
LM>// ARM 13.2 requires foo(int)
LM>double d = 26.7;
LM>bar(d); // both Symantec and g++ call bar(long double)
LM>// ARM 13.2 requires "ambiguous"
LM>char a = 28;
LM>int n = 29;
LM>rab(a); // both Symantec and g++ call rab(long) in both cases
LM>rab(n); // ARM 13.2 requires "ambiguous" in both cases.
LM>return 1;
LM>}
LM>//-------------
Borland C++ 4.0 complies to 13.2 on all 4 counts.
---
. OLX 2.2 . Plagarism prohibited. Derive carefully.