ORCA-C/Tests/Spec.Conform/SPC4.4.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

63 lines
2.0 KiB
C++

/* Special Conformance Test 4.4.1.1: Verification of ability to omit either */
/* type specifier or storage class in */
/* declarations, and both in function */
/* definitions (C89/C90 only) */
/* */
/* Other files needed: spc4411.exec - separately compiles, links, and */
/* executes the files spc4.4.1.1.cc and */
/* spc4411.1.cc */
/* */
int printf(const char *, ...);
static x; /* type of x is int */
float y; /* storage class of y is extern */
static F1 (); /* non-prototyped form: returns int */
double G1 (); /* also non-prototyped form: storage */
/* class is extern */
main ()
{
x = 0x7f << 2; /* if type is not int, error would be */
if (x != 0x1FC) /* flagged */
goto Fail1;
y = 8.7;
y = G1 (x);
if (y != 508.0)
goto Fail2;
x = F1 (3, 4);
if (x != 7)
goto Fail;
printf ("Passed Special Conformance Test 4.4.1.1\n");
return;
Fail:
printf ("Failed Special Conformance Test 4.4.1.1\n");
return;
Fail1:
printf ("extern int x not set correctly: x = %d\n", x);
goto Fail;
Fail2:
printf ("extern double function G1 returns incorrect value: y = %f\n", y);
goto Fail;
Fail3:
printf ("static int function F1 returns incorrect value: x = %d\n", x);
goto Fail;
}
/******************************************************************************/
F1 (x, y)
int x;
int y;
{
return x + y;
}