ORCA-C/Tests/Conformance/C7.7.1.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

51 lines
1.3 KiB
C++

/* Conformance Test 7.7.1.1: Verification of logical AND operator */
#include <stdio.h>
#include <math.h>
int main (void)
{
int i [3] = { 5, 6, 7 }, *i1ptr = i, *i2ptr = &i [2];
int j, k, m, n;
long L = 32777;
char ch = '!';
enum E { a, b, c };
unsigned int ui = 653;
unsigned long ul = 895;
unsigned char uch = 0x8;
float f = 3.5;
double d = 87.65;
extended e = 92.33;
/* Perform logical ANDs; test expected results. Left-to-right evaluation */
/* guaranteed. */
j = i [0] && i [2]; k = L && c; m = 0 && uch++; n = a && ch--;
if ((j != 1) || (k != 1) || (m != 0) || (n != 0) || (uch != 8) ||
(ch != '!'))
goto Fail;
j = f && (!d); k = --e && ++L; m = d && f; n = 0 && f--;
if ((j != 0) || (k != 1) || (m != 1) || (n != 0) ||
(fabs(e - 91.33) > 0.00001) || (L != 32778) || (fabs(f - 3.5) > 0.00001))
goto Fail;
j = i1ptr && i2ptr; k = 0 && (--i2ptr);
m = i2ptr && i1ptr++; n = i2ptr-- && 0;
if ((j != 1) || (k != 0) || (m != 1) || (n != 0) || (*i1ptr != 6) ||
(*i2ptr != 6))
goto Fail;
printf ("Passed Conformance Test 7.7.1.1\n");
return 0;
Fail:
printf ("Failed Conformance Test 7.7.1.1\n");
}