Path: utzoo!utgpu!water!watmath!clyde!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.lang.c Subject: Re: What does Z["ack"] = 5 mean? Message-ID: <276@lakart.UUCP> Date: 7 Oct 88 02:03:54 GMT References: <14999@agate.BERKELEY.EDU> Organization: Lakart Corporation - The ultimate in broadcast automation Lines: 32 From article <14999@agate.BERKELEY.EDU>, by laba-3aw@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@lakart.UUCP - David Goodenough +---+ | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart@harvard.harvard.edu +---+