dave@cs.arizona.edu (Dave P. Schaumann) (03/02/91)
In article <91059.215903DOCTORJ@SLACVM.SLAC.STANFORD.EDU> DOCTORJ@SLACVM.SLAC.STANFORD.EDU (Jon J Thaler) writes: >Regarding bounds checking... > >[method deleted] Bounds checking in arrays can be done quite easily in C++, by overloading the [] operator... (Just a thought. If you *really* need to do index checking, you might consider switching.) -- Dave Schaumann dave@cs.arizona.edu 'Dog Gang'! Where do they get off calling us the 'Dog Gang'? I'm beginning to think the party's over. I'm beginning to think maybe we don't need a dog. Or maybe we need a *new* dog. Or maybe we need a *cat*! - Amazing Stories
karl@ima.isc.com (Karl Heuer) (03/04/91)
In article <10362@dog.ee.lbl.gov> torek@elf.ee.lbl.gov (Chris Torek) writes: >[You need to use "foo(&iray)" to make the program type-correct] >(actually, given your defintion for DIM1 &c, it would probably be >clearer to write > for (i = 0; i < DIM1(*ray); ++i) Note that, if all mention of "ray" is via the construct "*ray" (I believe this is true given the above modification), it may be reasonable to use a reference rather than a pointer. C++ has builtin syntax for this; in C it can be emulated with a macro (using #undef to emulate scope): f(int (*ptr_ray)[5][1]) { #define jray (*ptr_ray) for (i = 0; i < DIM1(jray); ++i) ... jray[0][0] = ... #undef jray } This may clean up the perceived "ugliness" of the pointer-to-array code. Whether it's worth the added ugliness of the macro is a judgement call. Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint