Divide and C

D'Arcy J.M. Cain darcy at druid.uucp
Thu Mar 28 21:11:54 AEST 1991


In article <1991Mar27.185804.7221 at 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.

How about ZERO divides?  Use "++array[val];"  The following test program
works under GCC.

#include	<stdio.h>
int		main(void)
{
	int		a[10][10], *p, v = 24;

	p = (int *)(a);
	p[v] = 0x1234;
	printf("%x\n", a[2][4]);
	return(0);
}
-- 
D'Arcy J.M. Cain (darcy at druid)     |
D'Arcy Cain Consulting             |   There's no government
Toronto, Ontario, Canada           |   like no government!
+1 416 424 2871                    |



More information about the Comp.lang.c mailing list