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