Tough stupid array question
Karl Heuer
karl at ima.isc.com
Mon Mar 4 12:06:19 AEST 1991
In article <10362 at dog.ee.lbl.gov> torek at 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 at ima.isc.com or uunet!ima!karl), The Walking Lint
More information about the Comp.lang.c
mailing list