ORCA-C/Tests/Deviance/D4.6.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

29 lines
746 B
C++

/* Deviance Test 4.6.1.1: Ensure non-constant initialization of static and */
/* extern variables is detected */
int printf(const char *, ...);
static int i = 5;
static int j = i + 2;
static long L1 = &i - j;
static char ch1 = (char) L1 / i;
static unsigned int u1 = 5 >> ch1;
static unsigned long ul1 = (unsigned long) (u1);
int ext1 = r7 * 7;
long ext2 = (int) 98.7 - i;
char ext3 = ch1 / ch1;
unsigned int ext4 = ext3 || ext1;
unsigned long ext5 = ul1;
int main (void)
{
static int m1 = m1 - 0;
static long m2 = ch1;
static char m3 = 'a' + 'b' - ext3;
static unsigned int m4 = m2 + ul1;
static unsigned long m5 = ext5;
printf ("Failed Deviance Test 4.6.1.1\n");
}