mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-12-22 23:29:27 +00:00
6ead1d4caf
These are currently only run by the new DOIT3 test-running script. Note that these tests are designed to be applicable to most implementations of C95/C99/C11, not just ORCA/C. They do make certain assumptions not guaranteed by the standards (e.g. power of 2 types and some properties of IEEE-like FP), but in general those assumptions should be true for most 'normal' systems.
47 lines
960 B
C
47 lines
960 B
C
/*
|
|
* Test use of generic selection expressions (C11).
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#define g(x) _Generic((x), \
|
|
int: (x)+1, \
|
|
long: (x)+2, \
|
|
double: (x)+3, \
|
|
long double: (x)+4, \
|
|
unsigned char *: 100, \
|
|
int *: 101, \
|
|
default: 200 \
|
|
)
|
|
|
|
int main(void) {
|
|
int i;
|
|
|
|
if (g(12345) != 12346)
|
|
goto Fail;
|
|
|
|
if (g(1000000L) != 1000002)
|
|
goto Fail;
|
|
|
|
if (g(123.0) != 126.0)
|
|
goto Fail;
|
|
|
|
if (g(123.0L) != 127.0L)
|
|
goto Fail;
|
|
|
|
if (g((unsigned char*)&i) != 100)
|
|
goto Fail;
|
|
|
|
if (g(&i) != 101)
|
|
goto Fail;
|
|
|
|
if (g(123u) != 200)
|
|
goto Fail;
|
|
|
|
printf ("Passed Conformance Test c11generic\n");
|
|
return 0;
|
|
|
|
Fail:
|
|
printf ("Failed Conformance Test c11generic\n");
|
|
}
|