Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/andrew_beach_MMath/code/cond-catch.cfa

    rf79ee0d r54651005  
    33#include <exception.hfa>
    44#include <fstream.hfa>
    5 #include <stdlib.hfa>                                                                   // strto
     5#include <stdlib.h>
    66
    7 exception empty_exception;
    8 vtable(empty_exception) empty_vt;
     7EHM_EXCEPTION(empty_exception)();
     8
     9EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
    910
    1011bool should_catch = false;
     12
     13void throw_exception() {
     14        throw (empty_exception){&empty_vt};
     15}
     16
     17void cond_catch() {
     18        try {
     19                throw_exception();
     20        } catch (empty_exception * exc ; should_catch) {
     21                asm volatile ("# catch block (conditional)");
     22        }
     23}
    1124
    1225int main(int argc, char * argv[]) {
    1326        unsigned int times = 1;
    1427        if (1 < argc) {
    15                 times = strto(argv[1], 0p, 10);
     28                times = strtol(argv[1], 0p, 10);
    1629        }
    1730        if (2 < argc) {
    18                 should_catch = (unsigned int)strto(argv[2], 0p, 2);
     31                should_catch = strtol(argv[2], 0p, 10);
    1932        }
    2033
     
    2235        for (unsigned int count = 0 ; count < times ; ++count) {
    2336                try {
    24                         throw (empty_exception){&empty_vt};
    25                 } catch (empty_exception * exc ; should_catch) {
    26                         asm volatile ("# catch block (conditional)");
     37                        cond_catch();
    2738                } catch (empty_exception * exc) {
    2839                        asm volatile ("# catch block (unconditional)");
     
    3041        }
    3142        Time end_time = timeHiRes();
    32         sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
     43        sout | "Run-Time (ns): " | (end_time - start_time)`ns;
    3344}
Note: See TracChangeset for help on using the changeset viewer.