* as/mcs51/lkarea.c: removed old K&R style,
[fw/sdcc] / support / regression / tests / zeropad.c
index dbec36a224f8620e9a8d9b3f7e3c94eebc184584..f8f759da7456aa1cd0ef7545c11beaebf78d82d1 100644 (file)
@@ -1,11 +1,20 @@
 /** Zeropad tests.
 
-    storage: idata, xdata, code,
+    storage: idata, pdata, xdata, code,
 */
 #ifndef STORAGE
 #define STORAGE {storage}
 #endif
 
+#if defined __GNUC__
+  #define FLEXARRAY (__GNUC__ >= 3)
+  //since g fails on GCC 2.95.4 on alpha and I don't know how to detect alpha...
+  #define TEST_G    (__GNUC__ >= 3)
+#else
+  #define FLEXARRAY 1
+  #define TEST_G    1
+#endif
+
 #include <testfwk.h>
 
 typedef unsigned int size_t;
@@ -13,68 +22,76 @@ typedef unsigned int size_t;
 
 #if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80)
 # define idata
+# define pdata
 # define xdata
 # define code
 #endif
 
-char array[5] = {'a', 'b', 'c'};
+#if defined(SDCC_hc08)
+# define idata data
+# define pdata data
+#endif
 
-struct w {
-  char a;
-  int  b;
-} STORAGE g[3] = {
-  {'x', 1},
-  {'y'},
-  {'z', 3}
-};
+const char *string1 = "\x00\x01";
+const char string2[] = "\x00\x01";
+
+#ifndef PORT_HOST
+#pragma disable_warning 147 //no warning about excess initializers (W_EXCESS_INITIALIZERS)
+//array will be truncated but warning will be suppressed
+//if truncation is incorrect, other ASSERTs will fail with high probability
+char STORAGE trunc[2] = {'a', 'b', 'c'};
+#endif
+
+char STORAGE array[5] = {'a', 'b', 'c'};
+
+#if TEST_G
+  struct w {
+    char a;
+    int  b;
+  } STORAGE g[3] = {
+    {'x', 1},
+    {'y'},
+    {'z', 3}
+  };
+#endif
 
 struct x {
   short a;
   char  b[10];
 };
 
-struct y {
-  short a;
-  char  b[];
-};
-
-/* I think section 6.7.2.1 paragraph 2 of ISO/IEC 9899:1999 prohibits */
-/* nesting a structure ending in a flexible array inside another      */
-/* struct/union. In any case, my gcc (3.2.2) chokes on this. -- EEP   */
-#ifdef NESTED_FLEX_ARRAY
-struct z {
-  char     c;
-  struct y s;
-};
-#endif
-
 struct x STORAGE teststruct[5] = {
   { 10, {  1, 2, 3, 4, 5} },
   { 20, { 11 } },
   { 30, {  6, 7, 8} }
 };
 
+#if FLEXARRAY
+  struct y {
+    short a;
+    char  b[];
+  };
+
 struct y STORAGE incompletestruct = {
   10, {1, 2, 3, 4, 5}
 };
-
-#ifdef NESTED_FLEX_ARRAY
-struct z STORAGE nestedstruct = {
-  16,
-  {20, {6, 7, 8} }
-};
 #endif
 
 void
 testZeropad(void)
 {
+  ASSERT(string1[1] == '\x01');
+  ASSERT(string2[1] == '\x01');
+
   ASSERT(array[2] == 'c');
   ASSERT(array[4] == 0);
 
+#if TEST_G
   ASSERT(g[1].a == 'y');
   ASSERT(g[1].b == 0);
   ASSERT(g[2].a == 'z');
   ASSERT(g[2].b == 3);
+#endif
 
   ASSERT(teststruct[0].b[1] ==  2);
   ASSERT(teststruct[0].b[5] ==  0);
@@ -86,6 +103,7 @@ testZeropad(void)
   ASSERT(sizeof(teststruct[1])   == 12);
   ASSERT(sizeof(teststruct)      == 60);
 
+#if FLEXARRAY
   ASSERT(incompletestruct.a    == 10);
   ASSERT(incompletestruct.b[0] ==  1);
   ASSERT(incompletestruct.b[4] ==  5);
@@ -93,10 +111,5 @@ testZeropad(void)
   ASSERT(sizeof(incompletestruct) == sizeof(struct y));
   ASSERT(sizeof(incompletestruct) == offsetof(struct y, b));
   ASSERT(sizeof(incompletestruct) == offsetof(struct x, b));
-
-#ifdef NESTED_FLEX_ARRAY
-  ASSERT(nestedstruct.c      == 16);
-  ASSERT(nestedstruct.s.a    == 20);
-  ASSERT(nestedstruct.s.b[2] ==  8);
 #endif
 }