Ignore:
Timestamp:
Oct 13, 2024, 1:15:29 PM (5 weeks ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
4e0168a
Parents:
1a7203d
Message:

change CFA tests to use C designator syntax

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/designations.cfa

    r1a7203d rc565d68  
    1010// Created On       : Thu Jun 29 15:26:36 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun 29 11:31:21 2023
    13 // Update Count     : 28
     12// Last Modified On : Sun Oct 13 11:53:16 2024
     13// Update Count     : 31
    1414//
    1515
     
    1717
    1818// Note: this test case has been crafted so that it compiles with both cfa and with gcc without any modifications.
    19 // In particular, since the syntax for designations in Cforall differs from that of C, preprocessor substitution
    20 // is used for the designation syntax
    2119#ifdef __cforall
    22 #define _ :
    2320#define AT @
    2421#else
    25 #define _ =
    2622#define AT
    2723#endif
     
    10096        } m;
    10197};
    102 struct Fred s1 AT= { .m.j _ 3 };
    103 struct Fred s2 AT= { .i _ { [2] _ 2 } };
     98struct Fred s1 AT= { .m.j = 3 };
     99struct Fred s2 AT= { .i = { [2] = 2 } };
    104100
    105101int main() {
    106102        // simple designation case - starting from beginning of structure, leaves ptr default-initialized (zero)
    107103        struct A y0 = {
    108                 .x _ 2,
    109                 .y _ 3
     104                .x = 2,
     105                .y = 3
    110106        };
    111107
     
    118114        // use designation to move to member y, leaving x default-initialized (zero)
    119115        struct A y2 = {
    120                 .y _ 3,
     116                .y = 3,
    121117                0
    122118        };
     
    141137                { 3 }, // z1.a0
    142138                { 4 }, // z1.a1
    143                 .a0 _ { 5 }, // z1.a0
     139                .a0 = { 5 }, // z1.a0
    144140                { 6 }, // z1.a1
    145                 .a0.y _ 2, // z1.a0.y
     141                .a0.y = 2, // z1.a0.y
    146142                0, // z1.a0.ptr
    147143        };
     
    214210#endif
    215211        // array designation
    216         int i[2] = { [1] _ 3 };
     212        int i[2] = { [1] = 3 };
    217213        // allowed to have 'too many' initialized lists - essentially they are ignored.
    218214        int i1 = { 3 };
     
    220216        // doesn't work yet.
    221217        // designate unnamed object's members
    222         // struct D d = { .x _ 3 };
     218        // struct D d = { .x = 3 };
    223219#if ERROR
    224         struct D d1 = { .y _ 3 };
     220        struct D d1 = { .y = 3 };
    225221#endif
    226222
     
    242238        // move cursor to e4.b.a0.x and initialize until e3.b.a1.ptr inclusive
    243239        union E e3 = {
    244                 .b.a0.x _ 2, 3, 0, 5, 6, 0
     240                .b.a0.x = 2, 3, 0, 5, 6, 0
    245241        };
    246242
     
    261257        // more cases
    262258
    263 //      int widths[] = { [3 ... 9] _ 1, [10 ... 99] _ 2, [100] _ 3 };
    264 //      int widths[] = { [3 ~ 9] _ 1, [10 ~ 99] _ 2, [100] _ 3 };
     259//      int widths[] = { [3 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };
     260//      int widths[] = { [3 ~ 9] = 1, [10 ~ 99] = 2, [100] = 3 };
    265261        struct point { int x, y; };
    266         struct point p = { .y _ 5, .x _ 7 };
     262        struct point p = { .y = 5, .x = 7 };
    267263        union foo { int i; double d; };
    268         union foo f = { .d _ 4 };
     264        union foo f = { .d = 4 };
    269265        int v1, v2, v4;
    270         int w[6] = { [1] _ v1, v2, [4] _ v4 };
    271         int whitespace[256] = { [' '] _ 1, ['\t'] _ 1, ['\v'] _ 1, ['\f'] _ 1, ['\n'] _ 1, ['\r'] _ 1 };
    272         struct point ptarray[10] = { [2].y _ 34, [2].x _ 35, [0].x _ 36 };
     266        int w[6] = { [1] = v1, v2, [4] = v4 };
     267        int whitespace[256] = { [' '] = 1, ['\t'] = 1, ['\v'] = 1, ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 };
     268        struct point ptarray[10] = { [2].y = 34, [2].x = 35, [0].x = 36 };
    273269}
    274270
Note: See TracChangeset for help on using the changeset viewer.