mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-11-17 20:06:49 +00:00
91d33b586d
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.
103 lines
2.4 KiB
C++
103 lines
2.4 KiB
C++
/* Conformance Test 4.6.3.1: Verification of pointer initializers */
|
|
|
|
/* static and extern pointer variables can use only constant expressions */
|
|
|
|
#include <stddef.h>
|
|
|
|
int printf(const char *, ...);
|
|
|
|
struct S { int a;
|
|
float b; };
|
|
union U { int i;
|
|
long L; };
|
|
enum E { a, b, c };
|
|
|
|
static int *i1Ptr = NULL; /* constant expression can contain NULL */
|
|
static char *ch1Ptr = NULL;
|
|
static long *L1Ptr = NULL;
|
|
static comp *c1Ptr = NULL;
|
|
static float *f1Ptr = NULL;
|
|
static double *d1Ptr = NULL;
|
|
static extended *e1Ptr = NULL;
|
|
|
|
static unsigned int *ui1Ptr = NULL;
|
|
static unsigned long *uL1Ptr = NULL;
|
|
|
|
static struct S *struct1Ptr = NULL;
|
|
static union U *union1Ptr = NULL;
|
|
static enum E *enum1Ptr = NULL;
|
|
|
|
int *i2Ptr = NULL;
|
|
char *ch2Ptr = NULL;
|
|
long *L2Ptr = NULL;
|
|
comp *c2Ptr = NULL;
|
|
float *f2Ptr = NULL;
|
|
double *d2Ptr = NULL;
|
|
extended *e2Ptr = NULL;
|
|
|
|
unsigned int *ui2Ptr = NULL;
|
|
unsigned long *uL2Ptr = NULL;
|
|
|
|
struct S *struct2Ptr = NULL;
|
|
union U *union2Ptr = NULL;
|
|
enum E *enum2Ptr = NULL;
|
|
|
|
int main (void)
|
|
{
|
|
/* local pointer variables can also be set to NULL */
|
|
|
|
int *i3Ptr = NULL;
|
|
char *ch3Ptr = NULL;
|
|
long *L3Ptr = NULL;
|
|
comp *c3Ptr = NULL;
|
|
float *f3Ptr = NULL;
|
|
double *d3Ptr = NULL;
|
|
extended *e3Ptr = NULL;
|
|
|
|
unsigned int *ui3Ptr = NULL;
|
|
unsigned long *uL3Ptr = NULL;
|
|
|
|
struct S *struct3Ptr = NULL;
|
|
union U *union3Ptr = NULL;
|
|
enum E *enum3Ptr = NULL;
|
|
|
|
if ((i1Ptr != 0) || (i2Ptr != 0) || (i3Ptr != 0))
|
|
goto Fail;
|
|
|
|
if ((ch1Ptr != 0) || (ch2Ptr != 0) || (ch3Ptr != 0))
|
|
goto Fail;
|
|
|
|
if ((L1Ptr != 0) || (L2Ptr != 0) || (L3Ptr != 0))
|
|
goto Fail;
|
|
|
|
if ((c1Ptr != 0) || (c2Ptr != 0) || (c3Ptr != 0))
|
|
goto Fail;
|
|
|
|
if ((f1Ptr != 0) || (f2Ptr != 0) || (f3Ptr != 0))
|
|
goto Fail;
|
|
|
|
if ((d1Ptr != 0) || (d2Ptr != 0) || (d3Ptr != 0))
|
|
goto Fail;
|
|
|
|
if ((e1Ptr != 0) || (e2Ptr != 0) || (e3Ptr != 0))
|
|
goto Fail;
|
|
|
|
if ((ui1Ptr != 0) || (ui2Ptr != 0) || (ui3Ptr != 0))
|
|
goto Fail;
|
|
|
|
if ((uL1Ptr != 0) || (uL2Ptr != 0) || (uL3Ptr != 0))
|
|
goto Fail;
|
|
|
|
if ((struct1Ptr != 0) || (struct2Ptr != 0) || (struct3Ptr != 0))
|
|
goto Fail;
|
|
|
|
if ((union1Ptr != 0) || (union2Ptr != 0) || (union3Ptr != 0))
|
|
goto Fail;
|
|
|
|
printf ("Passed Conformance Test 4.6.3.1\n");
|
|
return 0;
|
|
|
|
Fail:
|
|
printf ("Failed Conformance Test 4.6.3.1\n");
|
|
}
|