Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/designations.cfa

    r2e0bb92 rc565d68  
    1010// Created On       : Thu Jun 29 15:26:36 2017
    1111// 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>
    1517
    1618// Note: this test case has been crafted so that it compiles with both cfa and with gcc without any modifications.
    17 #include <stdio.h>
    1819#ifdef __cforall
    1920#define AT @
     
    2223#endif
    2324
    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 
    3025const int indentAmt = 2;
    3126void indent( int level ) {
    32         printf( "%*s", level, "" );
     27        sout | wd( level, "" ) | nonl;
    3328}
    3429
     
    4035void printA( struct A a, int level ) {
    4136        indent( level );
    42         printf( "(A){ %d %d %p }\n", a.x, a.y, a.ptr );
     37        sout | "(A){ " | a.x | a.y | a.ptr | " }";
    4338}
    4439
     
    4944void printB( struct B b, int level ) {
    5045        indent( level );
    51         printf( "(B){\n" );
     46        sout | "(B){";
    5247        printA( b.a0, level+indentAmt );
    5348        printA( b.a1, level+indentAmt );
    5449        indent( level );
    55         printf( "}\n" );
     50        sout | "}";
    5651}
    5752
     
    6358void printC( struct C c, int level ) {
    6459        indent( level );
    65         printf( "(C){\n" );
     60        sout | "(C){";
    6661        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] | " }";
    6863        printB( c.b, level+indentAmt );
    6964        indent( level );
    70         printf( "}\n" );
     65        sout | "}";
    7166}
    7267
     
    7974void printD( struct D d, int level ) {
    8075        indent( level);
    81         printf( "(D){ %d }\n", d.x );
     76        sout | "(D){ " | d.x | "}";
    8277}
    8378
     
    10196        } m;
    10297};
    103 struct Fred s1 AT= { .m.j = { 3 } };
     98struct Fred s1 AT= { .m.j = 3 };
    10499struct Fred s2 AT= { .i = { [2] = 2 } };
    105100
     
    129124#endif
    130125
    131         printf( "=====A=====\n" );
     126        sout | "=====A=====";
    132127        printA( y0, 0 );
    133128        printA( y1, 0 );
    134129        printA( y2, 0 );
    135         printf( "=====A=====\n\n" );
     130        sout | "=====A=====" | nl | nl;
    136131
    137132        // initialize only first element (z0.a.x), leaving everything else default-initialized (zero), no nested curly-braces
     
    172167        };
    173168
    174         printf( "=====B=====\n" );
     169        sout | "=====B=====";
    175170        printB( z0, 0 );
    176171        printB( z1, 0 );
     
    179174        printB( z5, 0 );
    180175        printB( z6, 0 );
    181         printf( "=====B=====\n\n" );
     176        sout | "=====B=====" | nl | nl;
    182177
    183178        // TODO: what about extra things in a nested init? are empty structs skipped??
     
    190185        };
    191186
    192         printf( "=====C=====\n" );
     187        sout | "=====C=====";
    193188        printC( c1, 0 );
    194         printf( "=====C=====\n\n" );
     189        sout | "=====C=====" | nl | nl;
    195190
    196191#if ERROR
     
    216211        // array designation
    217212        int i[2] = { [1] = 3 };
    218 
    219213        // allowed to have 'too many' initialized lists - essentially they are ignored.
    220214        int i1 = { 3 };
     
    247241        };
    248242
    249         printf( "=====E=====\n" );
     243        sout | "=====E=====";
    250244        printA( e0.a, 0 );
    251245        printA( e1.a, 0 );
    252246        printA( e2.a, 0 );
    253247        printB( e3.b, 0 );
    254         printf( "=====E=====\n\n" );
     248        sout | "=====E=====" | nl | nl;
    255249
    256250        // special case of initialization: char[] can be initialized with a string literal
     
    260254        const char c3[] = { 'a', 'b', 'c' };
    261255        const char c4[][2] = { { 'a', 'b' }, { 'c', 'd'}, { 'c', 'd'} };
    262         const char ch = c4[0][0];
    263256
    264257        // more cases
     
    270263        union foo { int i; double d; };
    271264        union foo f = { .d = 4 };
    272         int v1 = 0, v2 = 0, v4 = 0;
     265        int v1, v2, v4;
    273266        int w[6] = { [1] = v1, v2, [4] = v4 };
    274267        int whitespace[256] = { [' '] = 1, ['\t'] = 1, ['\v'] = 1, ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 };
Note: See TracChangeset for help on using the changeset viewer.