Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!decwrl!nsc!amdahl!lamont From: lamont@uts.amdahl.com (Duane Richard LaMont) Newsgroups: comp.lang.c Subject: Re: Divide and C Message-ID: Date: 29 Mar 91 05:20:12 GMT References: <1991Mar27.185804.7221@uunet.uu.net> Reply-To: lamont@amdahl.uts.amdahl.com (Duane Richard LaMont) Organization: Amdahl Corporation, Sunnyvale CA Lines: 28 In article <1991Mar27.185804.7221@uunet.uu.net> karln!karln@uunet.uu.net (Karl Nicholas) writes: > EX: int array[10][10]; > val = 24; > ++array[val/10][val%10]; > > This is the only way I know how to do this. > My problem with it is that is requires TWO divides. > > Wanting my program to run almost twice as fast, I wrote an ASSEMBLY > lang subroutine, to be called from C. Considering that you've already resorted to assembly language, the following hack shouldn't bother you. Provided that the array is defined as in your example with both dimensions specified, you could use: ++((int *) array)[val]; or even: ++*(*array + val); However, if your program uses arrays of pointers to arrays of integers, the above won't work and there is no counterpart solution. See the FAQ if you don't know what I'm talking about. Rick LaMont