source: src/examples/min.c@ 08a40fd

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 08a40fd was 784deab, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

fix recursive include bug in shadow includes, major clean of examples, add several long long routines to prelude

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[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// min.c --
8//
9// Author : Richard C. Bilson
10// Created On : Wed May 27 17:56:53 2015
11// Last Modified By : Peter A. Buhr
[784deab]12// Last Modified On : Mon Jan 4 11:40:51 2016
13// Update Count : 26
[86bd7c1f]14//
15
[784deab]16#include "fstream.h"
[a0d9f94]17
[42dcae7]18forall( type T | { int ?<?( T, T ); } )
[3848e0e]19T min( const T t1, const T t2 ) {
[86bd7c1f]20 return t1 < t2 ? t1 : t2;
[784deab]21} // min
[a0d9f94]22
[784deab]23int main( void ) {
24 ofstream *sout = ofstream_stdout();
25 // char does not have less than.
26 int ?<?( char op1, char op2 ) { return (int)op1 < (int)op2; }
27
28 sout | "char\t\t\t" | 'z' | ' ' | 'a' | "\tmin " | min( 'z', 'a' ) | endl;
29 sout | "signed int\t\t" | 4 | ' ' | 3 | "\tmin " | min( 4, 3 ) | endl;
30 sout | "unsigned int\t\t" | 4u | ' ' | 3u | "\tmin " | min( 4u, 3u ) | endl;
31 sout | "signed long int\t\t" | 4l | ' ' | 3l | "\tmin " | min( 4l, 3l ) | endl;
32 sout | "unsigned long int\t" | 4ul | ' ' | 3ul | "\tmin " | min( 4ul, 3ul ) | endl;
33 sout | "signed long long int\t" | 4ll | ' ' | 3ll | "\tmin " | min( 4ll, 3ll ) | endl;
34 sout | "unsigned long long int\t" | 4ull | ' ' | 3ull | "\tmin " | min( 4ull, 3ull ) | endl;
35 sout | "float\t\t\t" | 4.0f | ' ' | 3.1f | "\tmin " | min( 4.0f, 3.1f ) | endl;
36 sout | "double\t\t\t" | 4.0 | ' ' | 3.1 | "\tmin " | min( 4.0, 3.1 ) | endl;
37 sout | "long double\t\t" | 4.0l | ' ' | 3.1l | "\tmin " | min( 4.0l, 3.1l ) | endl;
38} // main
[42dcae7]39
40// Local Variables: //
[86bd7c1f]41// tab-width: 4 //
[784deab]42// compile-command: "cfa min.c fstream.o iostream.o iterator.o" //
[42dcae7]43// End: //
Note: See TracBrowser for help on using the repository browser.