ADT
        aaron-thesis
        arm-eh
        ast-experimental
        cleanup-dtors
        deferred_resn
        demangler
        enum
        forall-pointer-decay
        jacob/cs343-translation
        jenkins-sandbox
        new-ast
        new-ast-unique-expr
        no_list
        persistent-indexer
        pthread-emulation
        qualifiedEnum
      
      
        
          | Last change
 on this file since 56de5932 was             d2887f7, checked in by Aaron Moss <a3moss@…>, 8 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 |  | 
|---|
| 19 | struct counter { int x; }; | 
|---|
| 20 |  | 
|---|
| 21 | counter& ?+=?( counter& c, one_t ) { ++c.x; return c; } | 
|---|
| 22 |  | 
|---|
| 23 | counter& ?-=?( counter& c, one_t ) { --c.x; return c; } | 
|---|
| 24 |  | 
|---|
| 25 | int 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.