source: translator/examples/swap.c @ 26a07a22

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 26a07a22 was 0b8cd722, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

fix uninitialized value, fix memory reads after frees

  • Property mode set to 100644
File size: 375 bytes
Line 
1extern "C" {
2    int printf( const char *, ... );
3}
4
5forall( type T )
6void swap( T *left, T *right ) {
7    T temp;
8    temp = *left;
9    *left = *right;
10    *right = temp;
11}
12
13int main() {
14    int x = 1, y = 2;
15    printf( "%d %d\n", x, y );
16    swap( &x, &y );
17    printf( "%d %d\n", x, y );
18}
19
20// Local Variables: //
21// compile-command: "../../bin/cfa swap.c" //
22// End: //
Note: See TracBrowser for help on using the repository browser.