diff options
Diffstat (limited to 'support/regression/tests/structflexarray.c')
| -rw-r--r-- | support/regression/tests/structflexarray.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/support/regression/tests/structflexarray.c b/support/regression/tests/structflexarray.c new file mode 100644 index 0000000..842e12f --- /dev/null +++ b/support/regression/tests/structflexarray.c @@ -0,0 +1,66 @@ +/* Check basic behaviour of "flexible array members" + */ +#include <testfwk.h> + +#if defined(__SUNPRO_C) || defined(__GNUC__) +#pragma pack(1) +#endif + +#if !defined(__SUNPRO_C) && (!defined(__GNUC__) || (defined(__GNUC__) && __GNUC__ >= 3)) +/* flexible array members not supported by gcc < 3 compiler + and seems not to be supported on SunPro C compiler */ +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(__SUNPRO_C) && (!defined(__GNUC__) || (defined(__GNUC__) && __GNUC__ >= 3)) + /* flexible array members not supported by gcc < 3 compiler + and seems not to be supported on SunPro C compiler */ + /* 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(__SUNPRO_C) && (!defined(__GNUC__) || (defined(__GNUC__) && __GNUC__ >= 3)) +/* flexible array members not supported by gcc < 3 compiler + and seems not to be supported on SunPro C compiler */ +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(__SUNPRO_C) && (!defined(__GNUC__) || (defined(__GNUC__) && __GNUC__ >= 3)) + /* flexible array members not supported by gcc < 3 compiler + and seems not to be supported on SunPro C compiler */ + /* test sizeof */ + ASSERT(sizeof(s21) == 2); + /* test allocation size */ +#if !defined(PORT_HOST) + ASSERT((char *) &s22 - (char *) &s21 == 2 + 5); +#endif +#endif +} |
