Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.std.c Subject: Re: Function calls Date: Fri, 06 Oct 2023 05:38:02 -0700 Organization: A noiseless patient Spider Lines: 56 Message-ID: <865y3kc4et.fsf@linuxsc.com> References: <86bkdddd20.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: dont-email.me; posting-host="0d66ad153fa8b33d210641d1146ceacc"; logging-data="1634076"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hpoXxBXCN4ybN+l5Flnftu5IlSf6I9BY=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:I2SrXJV5lUSWlbqxpmgA/iHNiaM= sha1:O3xUVT2lQ9zsQso3N+tpTNbSVmk= Xref: csiph.com comp.std.c:6582 James Kuyper writes: > On Wednesday, October 4, 2023 at 10:21:30?PM UTC-4, Tim Rentsch wrote: > >> r...@zedat.fu-berlin.de (Stefan Ram) writes: >> >>> A recent draft of the C specification says about "return": >>> >>> |A return statement terminates execution of the current >>> |function and returns control to its caller. >>> >>> . There's also a section "Function calls" in a recent draft. >>> I expect that this section says something similar, to the effect that >>> during the evaluation of a function call, control is transferred to >>> the called function, but I was not able to find such wording! >> >> AFAICT the C standard does not say explicitly that a function >> call gives or transfers control to the function being called. > > Section 6.9.1 is about function definitions,. while 6.5.2.2 is > about function calls, but 6.9.1 has several paragraphs of > specification about what happens when the function is called, and > the relevant one is: > > "After all parameters have been assigned, the compound statement > that constitutes the body of the function definition is executed." > (6.9.1p11). That is one relevant paragraph, but not the only relevant paragraph. Paragraph 10 of that section says On entry to the function, the size expressions of each variably modified parameter are evaluated and the value of each argument expression is converted to the type of the corresponding parameter as if by assignment. (Array expressions and function designators as arguments were converted to pointers before the call.) What we are looking for is something that says the function is "entered", that is, that control is transferred. It appears the C standard doesn't actually say that. In section 6.5.2.2, which describes function call expressions, the standard doesn't even explicitly say that a function call expression will call the function. The word "call" is used often in 6.5.2.2, but always as a noun, never a verb. So 6.5.2.2 says a lot about function calls, but never explicitly says that one takes place. I expect no one is confused or unsure about what semantics are intended for a function call expression. The question being asked is about whether the C standard does or should say that a transfer of control takes place (and if so, how explicitly). AFAICT the C standard makes no explicit statement that a function call expression causes a transfer of control, i.e., that at runtime the called function is "entered". What text in the standard says that a function call expression causes a transfer of control to take place? Or isn't there one?