mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-06-06 12:29:33 +00:00
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.
99 lines
3.1 KiB
C++
99 lines
3.1 KiB
C++
/* Conformance Test 4.3.0.1: Verification of auto, register, and static */
|
|
/* storage classes */
|
|
|
|
int printf(const char *, ...);
|
|
|
|
static long L1 (register int a1, float x1); /* test forward referencing */
|
|
/* at top level */
|
|
|
|
static extended ext = 3.678; /* ensure static variables */
|
|
static int j = 2; /* initialized correctly */
|
|
static int i; /* should automatically be */
|
|
/* set to zero */
|
|
|
|
int main (void)
|
|
{
|
|
static void V1 (void); /* test forward referencing within */
|
|
/* function */
|
|
long LL = 3;
|
|
|
|
if (ext != 3.678)
|
|
goto Fail;
|
|
|
|
{
|
|
int auto i = 10; /* this i hides top-level i */
|
|
for (; i < 15; i++)
|
|
{
|
|
V1 ();
|
|
switch (i)
|
|
{
|
|
case 10: if (j != 3)
|
|
goto Fail;
|
|
break;
|
|
|
|
case 11: if (j != 4)
|
|
goto Fail;
|
|
break;
|
|
|
|
case 12: if (j != 5)
|
|
goto Fail;
|
|
break;
|
|
|
|
case 13: if (j != 6)
|
|
goto Fail;
|
|
break;
|
|
|
|
case 14: if (j != 7)
|
|
goto Fail;
|
|
break;
|
|
|
|
default: goto Fail;
|
|
break;
|
|
|
|
} /* end switch */
|
|
} /* end for */
|
|
} /* end inner block */
|
|
|
|
if (i != 5) /* top-level i */
|
|
goto Fail;
|
|
|
|
for (i = 0; i < 7; i++) /* L0 should be init. to 10 with each */
|
|
{ /* pass through the for loop; F0 */
|
|
auto int L0 = 10; /* should be initialized once */
|
|
static float F0 = 1.0;
|
|
|
|
LL = L1 (L0, F0);
|
|
if (LL)
|
|
goto Fail;
|
|
F0 += 1.0;
|
|
if (F0 == 3.0)
|
|
break;
|
|
}
|
|
if (i != 1) /* test that F0 was not reset */
|
|
goto Fail;
|
|
|
|
printf ("Passed Conformance Test 4.3.0.1\n");
|
|
return 0;
|
|
|
|
Fail:
|
|
printf ("Failed Conformance Test 4.3.0.1\n");
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static long L1 (register int a1, float x1) /* ensure classification as */
|
|
{ /* register doesn't affect */
|
|
/* value of parameter */
|
|
if (a1 != 10) /* a1 should be 10 each time called */
|
|
return 1;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
static void V1 (void)
|
|
{
|
|
++i; j++; /* ensure i, j are visible */
|
|
}
|