File: structflexarray.c

package info (click to toggle)
cc1111 2.9.0-4
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 38,692 kB
  • ctags: 132,262
  • sloc: ansic: 442,650; cpp: 37,006; sh: 10,334; makefile: 5,511; asm: 5,279; yacc: 2,953; lisp: 1,524; perl: 807; awk: 493; python: 468; lex: 447
file content (58 lines) | stat: -rw-r--r-- 1,199 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Check basic behaviour of "flexible array members"
 */
#include <testfwk.h>

#if !defined __GNUC__ || __GNUC__ >= 3
/* flexible array members not supported by gcc < 3 */
struct str1
{
  char c;
  short i[];
};

struct str1 s11 = { 1, {2, 3} };
struct str1 s12 = { 4, {5, 6, 7} }; /* different size */
#endif

static void
testFlexibleArray1(void)
{
#if !defined __GNUC__ || __GNUC__ >= 3
  /* flexible array members not supported by gcc < 3 */
  /* test sizeof */
  ASSERT(sizeof(s11) == 1);
  /* test allocation size */
#if ! defined(PORT_HOST)
   ASSERT((char *) &s12 - (char *) &s11 == 1 + 4);
#endif
#endif
}


/* test initialisation with string */

#if !defined __GNUC__ || __GNUC__ >= 3
/* flexible array members not supported by gcc < 3 */
struct str2
{
  short s;
  char str2[];
};

struct str2 s21 = { 1, "sdcc" };
struct str2 s22 = { 2, "sdcc is great" }; /* different size */
#endif

static void
testFlexibleArray2(void)
{
#if !defined __GNUC__ || __GNUC__ >= 3
  /* flexible array members not supported by gcc < 3 */
  /* test sizeof */
  ASSERT(sizeof(s21) == 2);
  /* test allocation size */
#if ! defined(PORT_HOST)
   ASSERT((char *) &s22 - (char *) &s21 == 2 + 5);
#endif
#endif
}