ORCA-C/Tests/Conformance/C2.1.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

68 lines
1.8 KiB
C++

/* Conformance Test 2.1.0.1: Verification of character set */
int printf(const char *, ...);
int main (void)
{
char string1 [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char string2 [] = "abcdefghijklmnopqrstuvwxyz";
char string3 [] = "0123456789";
char string4 [] = " !\"#$%&\'()*+,-./";
char string5 [] = ":;<=>?@";
char string6 [] = "[\\]^_";
char string7 [] = "{|}~";
char string8 [] = "\b\t\v\f\r\a\?";
int encode, i;
/* Create a string variable from the required characters and check */
/* its contents against the ASCII encodings for the characters. */
for (i = 0, encode = 0x41; i < 26; i++, encode++)
if (string1 [i] != encode)
goto Fail;
for (i = 0, encode = 0x61; i < 26; i++, encode++)
if (string2 [i] != encode)
goto Fail;
for (i = 0, encode = 0x30; i < 10; i++, encode++)
if (string3 [i] != encode)
goto Fail;
for (i = 0, encode = 0x20; i < 15; i++, encode++)
if (string4 [i] != encode)
goto Fail;
for (i = 0, encode = 0x3A; i < 7; i++, encode++)
if (string5 [i] != encode)
goto Fail;
for (i = 0, encode = 0x5B; i < 5; i++, encode++)
if (string6 [i] != encode)
goto Fail;
for (i = 0, encode = 0x7B; i < 4; i++, encode++)
if (string7 [i] != encode)
goto Fail;
if (string8 [0] != 0x08)
goto Fail;
if (string8 [1] != 0x09)
goto Fail;
if (string8 [2] != 0x0B)
goto Fail;
if (string8 [3] != 0x0C)
goto Fail;
if (string8 [4] != 0x0D)
goto Fail;
if (string8 [5] != 0x07)
goto Fail;
if (string8 [6] != 0x3F)
goto Fail;
printf ("Passed Conformance Test 2.1.0.1\n");
return 0;
Fail:
printf ("Failed Conformance Test 2.1.0.1\n");
}