source: src/tests/counter.c @ 2248dc7

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change on this file since 2248dc7 was d2887f7, checked in by Aaron Moss <a3moss@…>, 7 years ago

Default increment/decrement operators defined in terms of one_t

  • Property mode set to 100644
File size: 909 bytes
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 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// counter.c --
8//
9// Author           : Aaron B. Moss
10// Created On       : Thu Feb 22 15:27:00 2018
11// Last Modified By : Aaron B. Moss
12// Last Modified On : Thu Feb 22 15:27:00 2018
13// Update Count     : 1
14//
15
16// Tests unified increment/decrement builtin functions.
17// Could be extended for other arithmetic unifications
18
19struct counter { int x; };
20
21counter& ?+=?( counter& c, one_t ) { ++c.x; return c; }
22
23counter& ?-=?( counter& c, one_t ) { --c.x; return c; }
24
25int main() {
26    counter c = { 42 };
27    c += 1;
28    ++c;
29    c++;
30    printf("%d\n", c.x);
31    c -= 1;
32    --c;
33    c--;
34    printf("%d\n", c.x);
35}
36
37// Local Variables: //
38// tab-width: 4 //
39// compile-command: "cfa counter.c" //
40// End: //
Note: See TracBrowser for help on using the repository browser.