Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!cs.utexas.edu!uwm.edu!uakari.primate.wisc.edu!ames!dftsrv!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: "array" vs. "&array" ? Message-ID: <21764@mimsy.umd.edu> Date: 11 Jan 90 15:41:25 GMT References: <24521@gryphon.COM> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 66 In article chuckp@ncr-fc.FtCollins.NCR.com (Chuck Phillips) writes: >Granted. But the question remains: "What is the compiler supposed to do when >the programmer askes for a pointer to something in the symbol table?" The language does not provide a means for the programmer to do such a thing (the language makes no statements about the internals of compilers, or even the existance of compilers, other than to require anything that pretends to implement C to follow some particular standard). >Personally I like the idea of hysterical electronic laughter, but was asking >what ANSI had specified. I think the case in question here is supposed to be this: 1 float arrf[3] = { 1.2, 2.3, 3.4 }; 2 3 foo() { 4 float **p; 5 6 p = &arrf; 7 } The question is `What is the appropriate response from a C implementation when it is fed this code?'; the answer is `Produce a diagnostic.' (In other words, `hysterical electronic laughter'.) Line 7, in particular, consists of: (/) = (//) & ; The LHS of the equal sign (marked `/') is in object context, hence remains unchanged. The RHS (`//') is in value context, but is complex. The first part is a unary `&', whose target is in object context: & Since it *is* an object, the `&' applies. The result is a value: This is a value in a value context, so it now remains unchanged. We now have = ; An assignment is correct ONLY IF THE TYPES OF THE LEFT AND RIGHT AND SIDES MATCH. Here they do not. A compiler must issue a diagnostic. This is either an error: the line is ignored, or a warning: the compiler makes a guess as to what the programmer intended. Many compilers follow Stephen Johnson's lead by making it a warning, and inserting a cast: = insert> (float **) ; The result of this cast is machine dependent. In order to decide what it does, we have to be told what machine (and possibly which implementation of the C language on that machine) is being used. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris