Ignore:
Timestamp:
Mar 21, 2018, 12:03:55 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, with_gc
Children:
a9b1b0c
Parents:
8669cd3
Message:

Update references test to include several commented lines

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/references.c

    r8669cd3 r101a4d2  
    4646
    4747int main() {
    48         int x = 123456, *p1 = &x, **p2 = &p1, ***p3 = &p2,
     48        int x = 123456, x2 = 789, *p1 = &x, **p2 = &p1, ***p3 = &p2,
    4949                &r1 = x,    &&r2 = r1,   &&&r3 = r2;
    5050        ***p3 = 3;                          // change x
    51         // ((int&)r3 = 3;                      // change x, ***r3
    5251        **p3 = &x;                          // change p1
    53         // ((int*&)&r3) = &x;                  // change r1, (&*)**r3
    5452        *p3 = &p1;                          // change p2
    55         // ((int**&)&&r3) = &p2;               // change r2, (&(&*)*)*r3
    56         // ((int***&)&&&r3) = p3;              // change r3 to p3, (&(&(&*)*)*)r3
    5753        int y = 0, z = 11, & ar[3] = { x, y, z };    // initialize array of references
    5854        // &ar[1] = &z;                        // change reference array element
     
    6258        // sizeof( &ar[1] ) == sizeof( int *); // is true, i.e., the size of a reference
    6359
     60        ((int*&)&r3) = &x;                  // change r1, (&*)**r3
     61        x = 3;
    6462        // test that basic reference properties are true - r1 should be an alias for x
    6563        printf("%d %d %d\n", x, r1, &x == &r1);
     
    7674        changeRef( r1 );
    7775        printf("%d %d\n", r1, x);
     76
     77        ((int&)r3) = 6;                       // change x, ***r3
     78        printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
     79        ((int*&)&r3) = &x2;                   // change r1 to refer to x2, (&*)**r3
     80        ((int&)r3) = 999;                     // modify x2
     81        printf("x = %d ; x2 = %d\n", x, x2);  // check that x2 was changed
     82        ((int**&)&&r3) = p2;                  // change r2, (&(&*)*)*r3
     83        ((int&)r3) = 12345;                   // modify x
     84        printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
     85        ((int***&)&&&r3) = p3;                // change r3 to p3, (&(&(&*)*)*)r3
     86        ((int&)r3) = 22222;                   // modify x
     87        printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
    7888
    7989        // test that reference members are not implicitly constructed/destructed/assigned
Note: See TracChangeset for help on using the changeset viewer.