Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/square.c

    r784deab r86bd7c1f  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan  5 18:08:20 2016
    13 // Update Count     : 21
     12// Last Modified On : Wed May 27 18:43:34 2015
     13// Update Count     : 2
    1414//
    1515
    16 #include "fstream.h"
     16extern "C" {
     17#include <stdio.h>
     18}
    1719
    1820forall( type T | { T ?*?( T, T ); } )
    1921T square( T t ) {
    2022        return t * t;
    21 } // square
     23}
     24
     25//char ?*?( char a1, char a2 ) {
     26//      return (char)( (int)a1 * (int)a2 );
     27//}
    2228
    2329int main() {
    24 #if 0
    25         ofstream *sout = ofstream_stdout();
    26         sout | "result of squaring 9 is " | endl;
    27 
    28         // char does not have multiplication.
    29         char ?*?( char a1, char a2 ) {
    30                 return (char)((int)a1 * (int)a2);
    31         } // ?*?
    32         char c = 9;
    33         sout | "char\t\t\t" | square( c ) | endl;
    34 
    35         sout | square( s ) | endl;
    36 #endif
    37         short int s = 9;
    38         square( s );
    39 #if 0
    40         signed int i = 9;
    41         sout | "signed int\t\t" | square( i ) | endl;
    42 
    43         unsigned int ui = 9;
    44         sout | "unsigned int\t\t" | square( ui ) | endl;
    45 
    46         long int li = 9;
    47         sout | "signed long int\t\t" | square( li ) | endl;
    48 
    49         unsigned long int uli = 9;
    50         sout | "unsigned long int\t" | square( uli ) | endl;
    51 
    52         signed long long int lli = 9;
    53         sout | "signed long long int\t" | square( lli ) | endl;
    54 
    55         unsigned long long int ulli = 9;
    56         sout | "unsigned long long int\t" | square( ulli ) | endl;
    57 
    58         float f = 9.0;
    59         sout | "float\t\t\t" | square( f ) | endl;
    60 
    61         double d = 9.0;
    62         sout | "double\t\t\t" | square( d ) | endl;
    63 
    64         long double ld = 9.0;
    65         sout | "long double\t\t" | square( ld ) | endl;
    66 #endif
    67 } // main
     30        char c = 5;
     31        short int s = 5;
     32        int i = 5;
     33        float f = 5.0;
     34        double d = 5.0;
     35//      printf( "result of square of 5 is %d\n", (char)square( c ) );
     36        printf( "result of square of 5 is %d\n", square( s ) );
     37        printf( "result of square of 5 is %d\n", square( i ) );
     38        printf( "result of square of 5 is %f\n", square( f ) );
     39        printf( "result of square of 5 is %f\n", square( d ) );
     40}
    6841
    6942// Local Variables: //
    7043// tab-width: 4 //
    71 // compile-command: "cfa square.c fstream.o iostream.o iterator.o" //
     44// compile-command: "cfa square.c" //
    7245// End: //
Note: See TracChangeset for help on using the changeset viewer.