What's a C expert?

Dave Myers dem at mead.UUCP
Fri Aug 25 00:06:49 AEST 1989


In article <1336 at atanasoff.cs.iastate.edu> hascall at atanasoff.cs.iastate.edu.UUCP (John Hascall) writes:
>In article <6057> paulc at microsoft.UUCP (Paul Canniff 2/1011) writes:
>}In article <12214 at well.UUCP> tmh at well.UUCP (Todd M. Hoff) writes:
> 
>}>           What do you need to know to be an expert C programmer?
> 
>}How about ... understands why a[i] equals i[a] and CAN EXPLAIN IT,
>
>    a[i] = *(a+i), i[a] = *(i+a), a+i = i+a
>


   Hmmm....  I don't claim to be a C expert, but let's take a trivial
case.  An array of anything with a size different from that of int
will do.

	int i;
	struct element {
		int x[BIGNUMBER];
	} a[WHATEVER];

	a[i] == *(a + (i * sizeof(element)))
	i[a] == *(i + (a * sizeof(int)))

	or

	a[i] == *(a + (i * sizeof(int) * BIGNUMBER))
	i[a] == *(i + (a * sizeof(int)))

   Clearly, these are not equal.  By the same (or at least a similar)
token, if you do,

	struct element *b;
	i = b;
	i++;
	b++;
	printf("%d", i == b);

you will get a 0, meaning that i and b were not incremented by the
same amount.

-- 
David Myers                                             (513) 865-1343   
Mead Data Central            This          Data Fabrication Technology
P.O. Box 933                 space               mead!dem at uccba.uc.edu
Dayton, Ohio  45401          available.             ...!uccba!mead!dem



More information about the Comp.lang.c mailing list