Groups | Search | Server Info | Login | Register


Groups > comp.std.c > #6582

Re: Function calls

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.std.c
Subject Re: Function calls
Date 2023-10-06 05:38 -0700
Organization A noiseless patient Spider
Message-ID <865y3kc4et.fsf@linuxsc.com> (permalink)
References <calls-20231004163135@ram.dialup.fu-berlin.de> <86bkdddd20.fsf@linuxsc.com> <dff9aa5c-bb01-48e8-8793-79af97775a5dn@googlegroups.com>

Show all headers | View raw


James Kuyper <jameskuyper@alumni.caltech.edu> 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?

Back to comp.std.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: Function calls Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-10-04 19:21 -0700
  Re: Function calls James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-10-05 20:50 -0700
    Re: Function calls Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-10-06 05:38 -0700
      Re: Function calls James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-10-06 18:04 -0700
        Re: Function calls Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-10-08 15:30 -0700

csiph-web