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 1db2c5be was
a0d9f94,
checked in by Peter A. Buhr <pabuhr@…>, 10 years ago
|
add compiler flag to driver, update examples, fix unnamed bit fields
|
-
Property mode set to
100644
|
File size:
539 bytes
|
Line | |
---|
1 | // "./cfa -g sum.c" |
---|
2 | // "./cfa -CFA sum.c > sum_out.c" |
---|
3 | // "gcc32 -g sum_out.c LibCfa/libcfa.a" |
---|
4 | |
---|
5 | extern "C" { |
---|
6 | int printf( const char *, ... ); |
---|
7 | } |
---|
8 | |
---|
9 | context sumable( type T ) { |
---|
10 | const T 0; |
---|
11 | T ?+?(T, T); |
---|
12 | T ?++(T*); |
---|
13 | [T] ?+=?(T*,T); |
---|
14 | }; |
---|
15 | |
---|
16 | forall( type T | sumable( T ) ) |
---|
17 | T sum( int n, T a[] ) { |
---|
18 | T total = 0; |
---|
19 | int i; |
---|
20 | for ( i = 0; i < n; i += 1 ) |
---|
21 | total = total + a[i]; |
---|
22 | return total; |
---|
23 | } |
---|
24 | |
---|
25 | int main() { |
---|
26 | int a[10]; |
---|
27 | for ( int i = 0; i < 10; ++i ) { |
---|
28 | a[i] = i; |
---|
29 | } |
---|
30 | printf( "the sum is %d\n", sum( 10, a ) ); |
---|
31 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.