restored else branch for other ports
[fw/sdcc] / support / regression / tests / structflexarray.c
1 /* Check basic behaviour of "flexible array members"
2  */
3 #include <testfwk.h>
4
5 struct str1
6 {
7   char c;
8   short i[];
9 };
10
11 struct str1 s11 = { 1, {2, 3} };
12 struct str1 s12 = { 4, {5, 6, 7} }; /* different size */
13
14 static void
15 testFlexibleArray1(void)
16 {
17   /* test sizeof */
18   ASSERT(sizeof(s11) == 1);
19   /* test allocation size */
20 #if ! defined(PORT_HOST)
21    ASSERT((char *) &s12 - (char *) &s11 == 1 + 4);
22 #endif
23 }
24
25
26 /* test initialisation with string */
27
28 struct str2
29 {
30   short s;
31   char str2[];
32 };
33
34 struct str2 s21 = { 1, "sdcc" };
35 struct str2 s22 = { 2, "sdcc is great" }; /* different size */
36
37 static void
38 testFlexibleArray2(void)
39 {
40   /* test sizeof */
41   ASSERT(sizeof(s21) == 2);
42   /* test allocation size */
43 #if ! defined(PORT_HOST)
44    ASSERT((char *) &s22 - (char *) &s21 == 2 + 5);
45 #endif
46 }