Changes in tests/designations.cfa [2e0bb92:c565d68]
- File:
-
- 1 edited
-
tests/designations.cfa (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/designations.cfa
r2e0bb92 rc565d68 10 10 // Created On : Thu Jun 29 15:26:36 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jan 28 21:49:50 2025 13 // Update Count : 82 14 // 12 // Last Modified On : Sun Oct 13 11:53:16 2024 13 // Update Count : 31 14 // 15 16 #include <fstream.hfa> 15 17 16 18 // Note: this test case has been crafted so that it compiles with both cfa and with gcc without any modifications. 17 #include <stdio.h>18 19 #ifdef __cforall 19 20 #define AT @ … … 22 23 #endif 23 24 24 #pragma GCC diagnostic ignored "-Wmissing-braces"25 #pragma GCC diagnostic ignored "-Woverride-init"26 #pragma GCC diagnostic ignored "-Wunused-variable"27 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"28 29 30 25 const int indentAmt = 2; 31 26 void indent( int level ) { 32 printf( "%*s", level, "" );27 sout | wd( level, "" ) | nonl; 33 28 } 34 29 … … 40 35 void printA( struct A a, int level ) { 41 36 indent( level ); 42 printf( "(A){ %d %d %p }\n", a.x, a.y, a.ptr );37 sout | "(A){ " | a.x | a.y | a.ptr | " }"; 43 38 } 44 39 … … 49 44 void printB( struct B b, int level ) { 50 45 indent( level ); 51 printf( "(B){\n" );46 sout | "(B){"; 52 47 printA( b.a0, level+indentAmt ); 53 48 printA( b.a1, level+indentAmt ); 54 49 indent( level ); 55 printf( "}\n" );50 sout | "}"; 56 51 } 57 52 … … 63 58 void printC( struct C c, int level ) { 64 59 indent( level ); 65 printf( "(C){\n" );60 sout | "(C){"; 66 61 indent( level+indentAmt ); 67 printf( "(int[]{ %d %d %d }\n", c.arr[0], c.arr[1], c.arr[2] );62 sout | "(int[]{ " | c.arr[0] | c.arr[1] | c.arr[2] | " }"; 68 63 printB( c.b, level+indentAmt ); 69 64 indent( level ); 70 printf( "}\n" );65 sout | "}"; 71 66 } 72 67 … … 79 74 void printD( struct D d, int level ) { 80 75 indent( level); 81 printf( "(D){ %d }\n", d.x );76 sout | "(D){ " | d.x | "}"; 82 77 } 83 78 … … 101 96 } m; 102 97 }; 103 struct Fred s1 AT= { .m.j = { 3 }};98 struct Fred s1 AT= { .m.j = 3 }; 104 99 struct Fred s2 AT= { .i = { [2] = 2 } }; 105 100 … … 129 124 #endif 130 125 131 printf( "=====A=====\n" );126 sout | "=====A====="; 132 127 printA( y0, 0 ); 133 128 printA( y1, 0 ); 134 129 printA( y2, 0 ); 135 printf( "=====A=====\n\n" );130 sout | "=====A=====" | nl | nl; 136 131 137 132 // initialize only first element (z0.a.x), leaving everything else default-initialized (zero), no nested curly-braces … … 172 167 }; 173 168 174 printf( "=====B=====\n" );169 sout | "=====B====="; 175 170 printB( z0, 0 ); 176 171 printB( z1, 0 ); … … 179 174 printB( z5, 0 ); 180 175 printB( z6, 0 ); 181 printf( "=====B=====\n\n" );176 sout | "=====B=====" | nl | nl; 182 177 183 178 // TODO: what about extra things in a nested init? are empty structs skipped?? … … 190 185 }; 191 186 192 printf( "=====C=====\n" );187 sout | "=====C====="; 193 188 printC( c1, 0 ); 194 printf( "=====C=====\n\n" );189 sout | "=====C=====" | nl | nl; 195 190 196 191 #if ERROR … … 216 211 // array designation 217 212 int i[2] = { [1] = 3 }; 218 219 213 // allowed to have 'too many' initialized lists - essentially they are ignored. 220 214 int i1 = { 3 }; … … 247 241 }; 248 242 249 printf( "=====E=====\n" );243 sout | "=====E====="; 250 244 printA( e0.a, 0 ); 251 245 printA( e1.a, 0 ); 252 246 printA( e2.a, 0 ); 253 247 printB( e3.b, 0 ); 254 printf( "=====E=====\n\n" );248 sout | "=====E=====" | nl | nl; 255 249 256 250 // special case of initialization: char[] can be initialized with a string literal … … 260 254 const char c3[] = { 'a', 'b', 'c' }; 261 255 const char c4[][2] = { { 'a', 'b' }, { 'c', 'd'}, { 'c', 'd'} }; 262 const char ch = c4[0][0];263 256 264 257 // more cases … … 270 263 union foo { int i; double d; }; 271 264 union foo f = { .d = 4 }; 272 int v1 = 0, v2 = 0, v4 = 0;265 int v1, v2, v4; 273 266 int w[6] = { [1] = v1, v2, [4] = v4 }; 274 267 int whitespace[256] = { [' '] = 1, ['\t'] = 1, ['\v'] = 1, ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 };
Note:
See TracChangeset
for help on using the changeset viewer.