Path: utzoo!utgpu!water!watmath!clyde!bellcore!faline!ulysses!allegra!mit-eddie!ll-xn!ames!sdcsvax!ucsdhub!hp-sdd!hplabs!hpcea!hpfcdc!boemker From: boemker@hpfcdc.UUCP Newsgroups: comp.lang.c Subject: Re: Question about type casting Message-ID: <5080011@hpfcdc.HP.COM> Date: 13 Jan 88 18:49:57 GMT References: <546@xyzzy.UUCP> Organization: HP Ft. Collins, Co. Lines: 26 Posted: Wed Jan 13 13:49:57 1988 > But even if we accept the dubious legality of the cast, which is > justified only by very broad interpretation of K&R, (how do you convert > a pointer-valued expression to an array-valued expression, anyway?), the > resulting expression being subscripted would have to be a temporary > array (with, for this reason, no aliases), and the whole assignment > becomes a monumentally obfuscated no-op. (In particular, it does *NOT* > by any remote stretch of the imagination initialize i.) > But clearly K&R did not intend to allow anything to be cast to array > type, since casts are defined as conversions, and the allowable > conversions do not include any that result in arrays. 1. I'm not so sure about K&R's intentions. True, a cast is a conversion, but the book does not explicitly define the set of legal conversions; it only lists conversions. The list is not necessarily complete. 2. Whenever an array identifier appears in an expression, it is treated as being a pointer to the first element of the array. Casting an expression as an array is just asking that expression to be used as a pointer to the base element of a (mutli-dimensional) rectangular collection of elements. Using an expression of type array is defined, and the object referenced is not the whole collection of elements but a pointer to the collection (pp. 195 bottom and 210 top). Saying that the resulting expression would have to be a temporary array does not make sense under K&R, and it shows a misunderstanding of its concept of arrays: every array expression of the form A[i] is equivalent to the pointer expression *(A+i).