Xref: utzoo comp.lang.misc:7533 comp.object:3256 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!hsdndev!cmcl2!sbcs!eeserv1.ic.sunysb.edu!jallen From: jallen@eeserv1.ic.sunysb.edu (Joseph Allen) Newsgroups: comp.lang.misc,comp.object Subject: Re: Type Systems and Dynamic Binding Message-ID: <1991Apr19.085233.2352@sbcs.sunysb.edu> Date: 19 Apr 91 08:52:33 GMT References: <3843@ssc-bee.ssc-vax.UUCP> <27313:Apr1623:30:0391@kramden.acf.nyu.edu> <17APR91.21054415@uc780.umd.edu> Sender: usenet@sbcs.sunysb.edu (Usenet poster) Organization: State University of New York at Stony Brook Lines: 36 In article <17APR91.21054415@uc780.umd.edu> cs450a03@uc780.umd.edu writes: >Let's say I was trying to implement a dynamically typed language in C. >(Of course, I wouldn't _really_ be that crazy :-) Let's say I wanted >to detect when, for instance, the addition of 2 integers produces an >invalid result. Let's say that I can not accept a severe performance >hit for this checking (most of the time, it's not going to happen. >When it does happen, I'm going to switch to float -- performance must >be better than floating point). >How do I do it? #define add(a,b) (a<0 && b<0 && a+b>=0 || a>=0 && b>=0 && a+b<0 ? error():a+b) :-) I believe C is not really the problem. What you want is for the processor to give an integer overflow signal so that the calculation can be repeated in floating point. Unfortunately most (all?) don't. Even in an interpretive language you'd have to: add bov error sub bov error mul bov error which is quite gross. -- #define h 23 /* Height */ /* jallen@ic.sunysb.edu (129.49.12.74) */ #define w 79 /* Width */ /* Amazing */ int i,r,b[]={-w,w,1,-1},d,a[w*h];m(p){a[p]=2;while(d=(p>2*w?!a[p-w-w]?1:0:0)|( p