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
        new-env
        no_list
        persistent-indexer
        pthread-emulation
        qualifiedEnum
        with_gc
      
      
        
          | Last change
 on this file since ed45af6 was             b63e376, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago | 
        
          | 
update refrat with new keywords, update examples, update separators for quoted strings
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1.6 KB | 
      
      
| Rev | Line |  | 
|---|
| [86bd7c1f] | 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 | // square.c -- | 
|---|
|  | 8 | // | 
|---|
|  | 9 | // Author           : Richard C. Bilson | 
|---|
|  | 10 | // Created On       : Wed May 27 17:56:53 2015 | 
|---|
|  | 11 | // Last Modified By : Peter A. Buhr | 
|---|
| [b63e376] | 12 | // Last Modified On : Tue Mar  8 22:05:48 2016 | 
|---|
|  | 13 | // Update Count     : 27 | 
|---|
| [86bd7c1f] | 14 | // | 
|---|
|  | 15 |  | 
|---|
| [d3b7937] | 16 | #include <fstream> | 
|---|
| [a0d9f94] | 17 |  | 
|---|
| [b63e376] | 18 | forall( otype T | { T ?*?( T, T ); } ) | 
|---|
| [a0d9f94] | 19 | T square( T t ) { | 
|---|
| [86bd7c1f] | 20 | return t * t; | 
|---|
| [784deab] | 21 | } // square | 
|---|
| [86bd7c1f] | 22 |  | 
|---|
| [a0d9f94] | 23 | int main() { | 
|---|
| [784deab] | 24 | #if 0 | 
|---|
|  | 25 | sout | "result of squaring 9 is " | endl; | 
|---|
|  | 26 |  | 
|---|
|  | 27 | // char does not have multiplication. | 
|---|
|  | 28 | char ?*?( char a1, char a2 ) { | 
|---|
|  | 29 | return (char)((int)a1 * (int)a2); | 
|---|
|  | 30 | } // ?*? | 
|---|
|  | 31 | char c = 9; | 
|---|
|  | 32 | sout | "char\t\t\t" | square( c ) | endl; | 
|---|
|  | 33 |  | 
|---|
|  | 34 | sout | square( s ) | endl; | 
|---|
|  | 35 | #endif | 
|---|
| [d3b7937] | 36 | short s = 9; | 
|---|
| [784deab] | 37 | square( s ); | 
|---|
|  | 38 | #if 0 | 
|---|
|  | 39 | signed int i = 9; | 
|---|
|  | 40 | sout | "signed int\t\t" | square( i ) | endl; | 
|---|
|  | 41 |  | 
|---|
|  | 42 | unsigned int ui = 9; | 
|---|
|  | 43 | sout | "unsigned int\t\t" | square( ui ) | endl; | 
|---|
|  | 44 |  | 
|---|
|  | 45 | long int li = 9; | 
|---|
|  | 46 | sout | "signed long int\t\t" | square( li ) | endl; | 
|---|
|  | 47 |  | 
|---|
|  | 48 | unsigned long int uli = 9; | 
|---|
|  | 49 | sout | "unsigned long int\t" | square( uli ) | endl; | 
|---|
|  | 50 |  | 
|---|
|  | 51 | signed long long int lli = 9; | 
|---|
|  | 52 | sout | "signed long long int\t" | square( lli ) | endl; | 
|---|
|  | 53 |  | 
|---|
|  | 54 | unsigned long long int ulli = 9; | 
|---|
|  | 55 | sout | "unsigned long long int\t" | square( ulli ) | endl; | 
|---|
|  | 56 |  | 
|---|
|  | 57 | float f = 9.0; | 
|---|
|  | 58 | sout | "float\t\t\t" | square( f ) | endl; | 
|---|
|  | 59 |  | 
|---|
|  | 60 | double d = 9.0; | 
|---|
|  | 61 | sout | "double\t\t\t" | square( d ) | endl; | 
|---|
|  | 62 |  | 
|---|
|  | 63 | long double ld = 9.0; | 
|---|
|  | 64 | sout | "long double\t\t" | square( ld ) | endl; | 
|---|
|  | 65 | #endif | 
|---|
|  | 66 | } // main | 
|---|
| [86bd7c1f] | 67 |  | 
|---|
|  | 68 | // Local Variables: // | 
|---|
|  | 69 | // tab-width: 4 // | 
|---|
| [d3b7937] | 70 | // compile-command: "cfa square.c" // | 
|---|
| [86bd7c1f] | 71 | // End: // | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.