ORCA-C/Tests/Conformance/c99fam.c
Stephen Heumann 6ead1d4caf Add a set of new tests for C95/C99/C11 features that we now support.
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.
2021-08-22 17:32:56 -05:00

50 lines
872 B
C

/*
* Test use of flexible array member (C99).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TEST_STRING "123456789"
struct S {
int i;
char s[];
};
int main(void) {
struct S s1, *sp;
s1.i = 123;
sp = &s1;
if (sp->i != 123)
goto Fail;
sp = malloc(sizeof(struct S) + sizeof(TEST_STRING));
if (!sp)
goto Fail;
*sp = s1; // only guaranteed to copy i
if (sp->i != 123)
goto Fail;
strcpy(sp->s, TEST_STRING);
if (strcmp (sp->s, TEST_STRING) != 0) {
free(sp);
goto Fail;
}
free(sp);
printf ("Passed Conformance Test c99fam\n");
return 0;
Fail:
printf ("Failed Conformance Test c99fam\n");
}