structflexarray.c

来自「sdcc是为51等小型嵌入式cpu设计的c语言编译器支持数种不同类型的cpu」· C语言 代码 · 共 59 行

C
59
字号
/* 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 */#endifstatic voidtestFlexibleArray1(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 */#endifstatic voidtestFlexibleArray2(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}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?