Imported Upstream version 2.9.0
[debian/cc1111] / support / regression / tests / structflexarray.c
1 /* Check basic behaviour of "flexible array members"
2  */
3 #include <testfwk.h>
4
5 #if !defined __GNUC__ || __GNUC__ >= 3
6 /* flexible array members not supported by gcc < 3 */
7 struct str1
8 {
9   char c;
10   short i[];
11 };
12
13 struct str1 s11 = { 1, {2, 3} };
14 struct str1 s12 = { 4, {5, 6, 7} }; /* different size */
15 #endif
16
17 static void
18 testFlexibleArray1(void)
19 {
20 #if !defined __GNUC__ || __GNUC__ >= 3
21   /* flexible array members not supported by gcc < 3 */
22   /* test sizeof */
23   ASSERT(sizeof(s11) == 1);
24   /* test allocation size */
25 #if ! defined(PORT_HOST)
26    ASSERT((char *) &s12 - (char *) &s11 == 1 + 4);
27 #endif
28 #endif
29 }
30
31
32 /* test initialisation with string */
33
34 #if !defined __GNUC__ || __GNUC__ >= 3
35 /* flexible array members not supported by gcc < 3 */
36 struct str2
37 {
38   short s;
39   char str2[];
40 };
41
42 struct str2 s21 = { 1, "sdcc" };
43 struct str2 s22 = { 2, "sdcc is great" }; /* different size */
44 #endif
45
46 static void
47 testFlexibleArray2(void)
48 {
49 #if !defined __GNUC__ || __GNUC__ >= 3
50   /* flexible array members not supported by gcc < 3 */
51   /* test sizeof */
52   ASSERT(sizeof(s21) == 2);
53   /* test allocation size */
54 #if ! defined(PORT_HOST)
55    ASSERT((char *) &s22 - (char *) &s21 == 2 + 5);
56 #endif
57 #endif
58 }