- Timestamp:
- Mar 19, 2018, 5:29:23 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- f810e09
- Parents:
- c5ce0ec (diff), 12db9e4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/tests
- Files:
-
- 2 edited
-
.expect/references.txt (modified) (1 diff)
-
references.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/tests/.expect/references.txt
rc5ce0ec rd2034b4 28 28 Destructing a Y 29 29 Destructing a Y 30 3 3 31 3 32 3 33 3 9 { 1, 7 }, [1, 2, 3] 30 34 Destructing a Y 31 35 Destructing a Y -
src/tests/references.c
rc5ce0ec rd2034b4 49 49 &r1 = x, &&r2 = r1, &&&r3 = r2; 50 50 ***p3 = 3; // change x 51 // ((int&)r3 = 3; // change x, ***r3 51 52 **p3 = &x; // change p1 53 // ((int*&)&r3) = &x; // change r1, (&*)**r3 52 54 *p3 = &p1; // change p2 55 // ((int**&)&&r3) = &p2; // change r2, (&(&*)*)*r3 56 // ((int***&)&&&r3) = p3; // change r3 to p3, (&(&(&*)*)*)r3 53 57 int y = 0, z = 11, & ar[3] = { x, y, z }; // initialize array of references 58 // &ar[1] = &z; // change reference array element 59 // typeof( ar[1] ) p; // is int, i.e., the type of referenced object 60 // typeof( &ar[1] ) q; // is int &, i.e., the type of reference 61 // sizeof( ar[1] ) == sizeof( int ); // is true, i.e., the size of referenced object 62 // sizeof( &ar[1] ) == sizeof( int *); // is true, i.e., the size of a reference 54 63 55 64 // test that basic reference properties are true - r1 should be an alias for x … … 76 85 &z1.r = &z1r; 77 86 &z2.r = &z2r; 87 78 88 z1 = z2; 89 90 // test rvalue-to-reference conversion 91 { 92 struct S { double x, y; }; 93 void f( int & i, int & j, S & s, int v[] ) { 94 printf("%d %d { %g, %g }, [%d, %d, %d]\n", i, j, s.[x, y], v[0], v[1], v[2]); 95 } 96 void g(int & i) { printf("%d\n", i); } 97 void h(int &&& i) { printf("%d\n", i); } 98 99 int &&& r = 3; // rvalue to reference 100 int i = r; 101 printf("%d %d\n", i, r); // both 3 102 103 g( 3 ); // rvalue to reference 104 h( (int &&&)3 ); // rvalue to reference 105 106 int a = 5, b = 4; 107 f( 3, a + b, (S){ 1.0, 7.0 }, (int [3]){ 1, 2, 3 } ); // two rvalue to reference 108 } 79 109 } 80 110
Note:
See TracChangeset
for help on using the changeset viewer.