Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: dave_thompson_2@comcast.net Newsgroups: comp.compilers Subject: Re: What is the meaning of an expression? Date: Sun, 30 Jan 2022 22:51:54 -0500 Organization: A noiseless patient Spider Lines: 35 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <22-01-121@comp.compilers> References: <22-01-052@comp.compilers> <22-01-060@comp.compilers> <22-01-066@comp.compilers> <22-01-067@comp.compilers> <22-01-068@comp.compilers> <22-01-069@comp.compilers> <22-01-070@comp.compilers> <22-01-076@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="40505"; mail-complaints-to="abuse@iecc.com" Keywords: C, history Posted-Date: 31 Jan 2022 10:35:15 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:2878 On Thu, 20 Jan 2022 13:02:34 +0100, Hans-Peter Diettrich wrote: ... > ARAIR K&R C defined the value of a function call to be the value > contained in the accumulator after return. A decision with horrible > consequences if you look at compiler and library source code of that > time. OTOH it derogates the meaning of an expression if at any time one > can find a value in the defined result register. ... > [Early C didn't have default return values, but since the compilers also > didn't do much type checking, I can believe there was a code that > worked by accident becaues the value of the last expression in a function > happened to be in the register where the caller looked for the result. ...] Through K&R1 C didn't have 'void' -- all functions had some return type, which if not written defaulted to 'int' (as in BCPL and B). The _compilers_ did typecheck but not most _linkers_ so a mismatch across separately-compiled files was one way to get this problem; one of the features of 'lint' was to catch such. (FORTRAN had the same issue, and there were some tools for it, but I don't recall one as prominent. COBOL, at least then, didn't have value-returning subprograms, although it could have mismatch on arguments. I don't recall what Pascals did -- when they had separate compilation at all -- and never saw a non-toy algol. C++ overloading effectively required typesafe linkage, and Ada assumed a 'repository' preventing mismatches.) Another way is if you 'fall off the end' of a (non-void) function, or through the first standard (C89/90) you wrote and executed a return statement with no expression; before void this was widely used for functions with no useful value. If the callsite doesn't discard the notional 'value' of a call that does one of these, it is officially undefined behavior and in practice usually takes whatever value is lying about in the register used by the calling sequence -- but on PDP-11 and Interdata at least that wasn't 'the accumulator' because they had no such thing.