source: src/tests/polymorphism.c @ 598f50e

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 598f50e was 598f50e, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Update polymorphism test

  • Property mode set to 100644
File size: 869 bytes
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// polymorphism.c --
8//
9// Author           : Rob Schluntz
10// Created On       : Tue Oct 17 12:19:48 2017
11// Last Modified By : Rob Schluntz
12// Last Modified On : Tue Oct 17 12:21:07 2017
13// Update Count     : 1
14//
15
16forall(otype T)
17T f(T x, T y) {
18        x = y;
19        return x;
20}
21
22forall(otype T) T ident(T x) {
23        return x;
24}
25
26int main() {
27        // ensure that x is not changed by the invocation of a polymorphic function
28        int x = 123;
29        int y = 456;
30        int z = f(x, y);
31        printf("%d %d %d\n", x, y, z);
32
33        // explicitly specialize function
34        int (*f)(int) = ident;
35        ((int(*)(int))ident);
36        printf("%d %d\n", f(5), ((int(*)(int))ident)(5));
37}
38
39// Local Variables: //
40// tab-width: 4 //
41// End: //
Note: See TracBrowser for help on using the repository browser.