What does Z["ack"] = 5 mean?

David Goodenough dg at lakart.UUCP
Fri Oct 7 12:03:54 AEST 1988


>From article <14999 at agate.BERKELEY.EDU>, by laba-3aw at web.berkeley.edu (Sam Shen):
> Exactly what does this mean:
> 
> main()
> {
> 	char Z;
> 
> 	Z["ack!"] = 5;
> }
> 
> This doesn't look right to me.

Given that a[b] is (in some compilers [1]) considered to be *(a+b), your
Z["ack!"] = 5 can be considered as *("ack!" + Z) = 5, which equates to
"ack!"[Z] = 5. OK so far - this will work on most machines where strings
do not become part of a write only memory segment (Do any architectures
exist where strings become shared and read only??). Reading such a value
however, should be legal (at least that's what I interpret K&R to say).

[1] It is interesting to note that Greenhills CC (what we have here)
chokes on this sort of thing, generating the following:

"foo.c", line 5: Indexing not allowed
"foo.c", line 5: Type mismatch

Is this compiler broken W.R.T. dpANSI?? (not that I do this, it just happens
a lot in the obfuscated C contest :-)
-- 
	dg at lakart.UUCP - David Goodenough		+---+
							| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart at harvard.harvard.edu		  	  +---+



More information about the Comp.lang.c mailing list