ORCA-C/Tests/Spec.Conform/SPC13.4.0.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

76 lines
2.3 KiB
C++

/* */
/* Special Conformance Test 13.4.0.1: Verification of stdarg library facility */
/* */
/* The tester needs to verify that the values 2, 'c', 1.3, 4.4, and 7.7 are */
/* printed to standard out. */
/* */
#pragma optimize -1
#include <stdarg.h>
int printf(const char *, ...);
enum types { integer, character, singlePrecision, doublePrecision,
extendedPrecision, endOfList };
int main (void)
{
int i = 2;
char ch = 'c';
float f = 1.3;
double d = 4.4;
extended e = 7.7;
enum types typesArray [80];
void VariablePrint ( enum types *typesArray, ... );
typesArray [0] = integer; /* init. array of types of values */
typesArray [1] = character; /* to print */
typesArray [2] = singlePrecision;
typesArray [3] = doublePrecision;
typesArray [4] = extendedPrecision;
typesArray [5] = endOfList;
VariablePrint ( typesArray, i, ch, f, d, e ); /* call function which takes */
} /* variable number args */
/****************************************************************************/
void VariablePrint ( enum types *typesArray, ... )
{
va_list ap;
enum types nextType;
va_start (ap, typesArray); /* initialize variable argument ptr */
while ( (nextType = *typesArray++) != endOfList )
{
switch (nextType)
{
case integer:
printf ("int: %d\n", va_arg (ap, int));
break;
case character:
printf ("char: %c\n", va_arg (ap, int));
break;
case singlePrecision:
case doublePrecision:
case extendedPrecision:
printf ("extended: %e\n", va_arg (ap, extended));
break;
default:
printf ("Error in VariablePrint");
break;
} /* end switch */
} /* end while */
va_end (ap); /* clean up stack, etc. */
}