Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hpda!hpcupt1!hpisod2!decot From: decot@hpisod2.HP.COM (Dave Decot) Newsgroups: comp.lang.c Subject: Re: Yet Another Silly Question Message-ID: <2550091@hpisod2.HP.COM> Date: 23 May 89 05:05:38 GMT References: <6458@sdcsvax.UCSD.Edu> Organization: Hewlett Packard, Cupertino Lines: 30 > int a[MAX]; int a[MAX]; > int i; int *p; > for (i=0; i a[i] = 0; *p=0; > > ... > > ... On some compiler/machine combinations, this will run faster, > because the scaling operation and base/offset addition have been > eliminated; on others it may run slower, because a specific addressing > mode cannot be used. Note that the scaling operation has not necessarily been completely eliminated; it may have become hidden in "++p" because increments by 1 may be much faster than increments by sizeof(*p). Anyway, if one is interested in permitting high performance, one might as well give the compiler complete latitude to do this efficiently by rewriting this as: static struct { int i[MAX]; } a_, zero; int *a = &a_.i[0]; ... a_ = zero; :-) :-) :-) :-) :-) :-) :-) :-) Dave "Equal rights for arrays, NOW!" Decot