Ignore:
Timestamp:
Nov 3, 2014, 4:38:08 PM (10 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
8c17ab0
Parents:
93885663
Message:

add compiler flag to driver, update examples, fix unnamed bit fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/examples/iostream.c

    r93885663 r134b86a  
    66
    77#include "iostream.h"
    8 #undef __cplusplus
    98extern "C" {
    10 #include <string.h>
    11 #include <ctype.h>
    129#include <stdio.h>
     10//#include <string.h>
     11//#include <ctype.h>
     12typedef long unsigned int size_t;
     13size_t strlen(const char *s);
    1314}
    1415
    1516forall( dtype ostype | ostream( ostype ) )
    16 ostype *
    17 ?<<?( ostype *os, char c )
    18 {
    19   return write( os, &c, 1 );
     17ostype * ?<<?( ostype *os, char c ) {
     18    return write( os, &c, 1 );
    2019}
    2120
    2221forall( dtype ostype | ostream( ostype ) )
    23 ostype *
    24 ?<<?( ostype *os, int i )
    25 {
    26   char buffer[20];      // larger than the largest integer
    27   sprintf( buffer, "%d", i );
    28   return write( os, buffer, strlen( buffer ) );
     22ostype * ?<<?( ostype *os, int i ) {
     23    char buffer[20];      // larger than the largest integer
     24    sprintf( buffer, "%d", i );
     25    return write( os, buffer, strlen( buffer ) );
    2926}
    3027
    3128forall( dtype ostype | ostream( ostype ) )
    32 ostype *
    33 ?<<?( ostype *os, const char *cp )
    34 {
    35   return write( os, cp, strlen( cp ) );
     29ostype * ?<<?( ostype *os, double d ) {
     30    char buffer[32];      // larger than the largest double
     31    sprintf( buffer, "%g", d );
     32    return write( os, buffer, strlen( buffer ) );
     33}
     34
     35forall( dtype ostype | ostream( ostype ) )
     36ostype * ?<<?( ostype *os, const char *cp ) {
     37    return write( os, cp, strlen( cp ) );
    3638}
    3739
    3840forall( dtype istype | istream( istype ) )
    39 istype *
    40 ?>>?( istype *is, char *cp )
    41 {
    42   return read( is, cp, 1 );
     41istype * ?>>?( istype *is, char *cp ) {
     42    return read( is, cp, 1 );
    4343}
    4444
    4545forall( dtype istype | istream( istype ) )
    46 istype *
    47 ?>>?( istype *is, int *ip )
    48 {
    49   char cur;
     46istype * ?>>?( istype *is, int *ip ) {
     47    char cur;
    5048 
    51   // skip some whitespace
    52   do {
    53     is >> &cur;
    54     if( fail( is ) || eof( is ) ) return is;
    55   } while( !( cur >= '0' && cur <= '9' ) );
     49    // skip some whitespace
     50    do {
     51        is >> &cur;
     52        if( fail( is ) || eof( is ) ) return is;
     53    } while( !( cur >= '0' && cur <= '9' ) );
    5654 
    57   // accumulate digits
    58   *ip = 0;
    59   while( cur >= '0' && cur <= '9' ) {
    60     *ip = *ip * 10 + ( cur - '0' );
    61     is >> &cur;
    62     if( fail( is ) || eof( is ) ) return is;
    63   }
     55    // accumulate digits
     56    *ip = 0;
     57    while( cur >= '0' && cur <= '9' ) {
     58        *ip = *ip * 10 + ( cur - '0' );
     59        is >> &cur;
     60        if( fail( is ) || eof( is ) ) return is;
     61    }
    6462 
    65   unread( is, cur );
    66   return is;
     63    unread( is, cur );
     64    return is;
    6765}
Note: See TracChangeset for help on using the changeset viewer.