Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site x.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!cybvax0!frog!x!john From: john@x.UUCP (John Woods) Newsgroups: net.lang.c Subject: Re: Casting for a fish that never arrived Message-ID: <502@x.UUCP> Date: Wed, 15-May-85 15:13:50 EDT Article-I.D.: x.502 Posted: Wed May 15 15:13:50 1985 Date-Received: Fri, 17-May-85 04:53:42 EDT References: <864@aplvax.UUCP> Organization: Charles River Data Systems, Framingham MA Lines: 49 > /*-----------------------------------------------------------------------*/ > > char *Cwords[2][4] = { > {"hello","go","here","see"}, > {"goodbye","come","there","hear"} > }; > char *Pwords[2][4] = { > {"foo","foo","foo","foo"}, > {"foobar","foobar","foobar","foobar"} > }; > char *Words; > Words = Cwords; dot dot dot > printf("%s\n",(CASTING EXPRESSION)Words[i][j]); > > Here is a solution which works. I find it hard to believe this > can't be done without a typedef (or explicit pointer arithmetic), but > haven't been able to find a way yet. > > typedef char *SYNTAX[4]; > SYNTAX Cwords[2] = { > SYNTAX Pwords[2] = { > SYNTAX *Words; Well, I personally prefer the typedef style, but you didn't have to use it. The basic problem in the first example is that Words should not be of type char *; if Words were declared as a pointer to an array of four char pointers, e.g. char *(*Words)[4]; then you could use Words[i][k] without any casting required. I *THINK* I have the parentheses in the right place, and some quick cc -S experiments seem to make me believe I am right. However, that is the very reason that I prefer the typedef: with typedef, you can express these things quickly and easily. Reminds me of the old puzzle about casting the number 7 into a pointer to a function returning a pointer to a pointer to a function returning...... The answer took up about 70 characters on a single line, and looked like the output from crypt(1). The puzzle, of course, forbade the use of typedef, which made it much too easy!-) -- John Woods, Charles River Data Systems, Framingham MA, (617) 626-1101 ...!decvax!frog!john, ...!mit-eddie!jfw, jfw%mit-ccc@MIT-XX.ARPA "MU" said the Sacred Chao...