ORCA-C/Tests/Conformance/C4.6.2.1.CC
Stephen Heumann 91d33b586d Fix various C99+ conformance issues and bugs in test cases.
The main changes made to most tests are:

*Declarations always include explicit types, not relying on implicit int. The declaration of main in most test programs is changed to be "int main (void) {...}", adding an explicit return type and a prototype. (There are still some non-prototyped functions, though.)

*Functions are always declared before use, either by including a header or by providing a declaration for the specific function. The latter approach is usually used for printf, to avoid requiring ORCA/C to process stdio.h when compiling every test case (which might make test runs noticeably slower).

*Make all return statements in non-void functions (e.g. main) return a value.

*Avoid some instances of undefined behavior and type errors in printf and scanf calls.

Several miscellaneous bugs are also fixed.

There are still a couple test cases that intentionally rely on the C89 behavior, to ensure it still works.
2022-10-17 20:17:24 -05:00

72 lines
1.6 KiB
C++

/* Conformance Test 4.6.2.1: Verification of floating-point initializers */
/* static and extern variables are restricted to constant expressions */
#include <math.h>
int printf(const char *, ...);
static float f1 = -1.0E2 + (float) 2 * 5.0 / 20.0 - (double) 6;
static double d1 = 89.76E5 * 17.6 - (extended) 1 + (float) (-3) / 8.;
static extended e1 = 9.9 * 7.1 + 0.03 - (extended) 2 / (float) (0 && 3.0 || 2);
float f2 = 5.1 * 7 - 88 / 4 + (extended) (double) (float) 8;
double d2 = 10.0e20 / 0.04E-6;
extended e2 = 15.5 - .5 * 3 + 1;
int main (void)
{
/* auto and register variables can use any arithmetic expression */
float f3 = f1 * f2 / 1;
double d3 = 8.1;
{ extended e3 = e1 && e2 || d3 - f3;
{ register float f4 = f3;
register double d4 = f3 / 2.0;
{ register extended e4 = d4 + (extended) 8.88 - f1 / 5.0;
if (fabs(f1 - (-105.5)) > 0.00001)
goto Fail;
if (fabs(f2 - 21.7) > 0.00001)
goto Fail;
if (fabs(f3 - (-2289.35)) > 0.001)
goto Fail;
if (fabs(f4 - (-2289.35)) > 0.001)
goto Fail;
if (fabs(d1 - 157977600.0) > 100.0)
goto Fail;
if (fabs(d2 - 2.5e28) > 1e21)
goto Fail;
if (fabs(d3 - 8.1) > 0.00001)
goto Fail;
if (fabs(d4 - (-1144.675)) > 0.01)
goto Fail;
if (fabs(e1 - 68.32) > 0.0001)
goto Fail;
if (fabs(e2 - 15.0) > 0.0001)
goto Fail;
if (fabs(e3 - 1.0) > 0.00001)
goto Fail;
if (fabs(e4 - (-1114.695)) > 0.001)
goto Fail;
printf ("Passed Conformance Test 4.6.2.1\n");
return 0;
Fail:
printf ("Failed Conformance Test 4.6.2.1\n");
}}}
}