Post by James Kuyper...
Post by Tim RentschPost by James KuyperPost by Tim RentschAFAICT 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
"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.)
Yes, I mentioned that - "several paragraphs of specification about
what happens when the function is called".
Specificaly, paragraphs 10, 11, and 12 give the semantics for when
a function definition is elaborated. Note that the Standard does
not say that these paragraphs are about what happens when the
function is called, but what happens when the function is entered.
It may be that the intention is to say what happens when the
function is called, but the Standard doesn't say that. Paragraph 10
starts "On entry ..."; it does not say "On being called ...".
Post by James KuyperPost by Tim RentschWhat we are looking for is something that says the function is
"entered", that is, that control is transferred.
I find it confusing that you think something more needs to be
specified.
I never said I think that. My guess is you didn't give full
attention to the second paragraph of my first posting (and which
you left out of your reply), which makes clear that I am asking
questions of the OP, and not stating a position of my own. I
don't have a dog in this fight.
Post by James KuyperThe standard specifies that the compound statement that
constitutes the body of the function gets executed.
No, it doesn't. What the Standard does say is that the function
body (i.e., the compound statement that constitutes the body
thereof) gets executed /if and when the function is entered/.
No entry, no execution. The issue is Does the Standard say the
function is entered (or called)? Apparently the Standard does
not explicitly say that.
Note that every other state-changing construct (or at least those I
could think of: ++, --, assignment, if(), switch(), for(), do,
while(), goto, break, continue, and most notably return) describe
their semantics using a transitive verb (sometimes using the passive
voice, but a transitive verb nonetheless). The semantic description
of function call expressions does not use any such constructions for
the action of calling the function (although there are several
transitive verbs for actions that take place /before/ calling the
function). Because the description of return says "A return
statement terminates execution of the current function and returns
control to its caller", it isn't surprising that some people expect
to find some sort of similar wording about transferring control in
the description of semantics for function call expressions (and in
particular the OP did have such an expectation). But there isn't
any.
Post by James KuyperCould you explain how that differs from having control transferred
to the function? Please give an example of what it would mean to
have the compound statement executed without transferring control.
This question is moot because it starts from a false assumption.
Post by James KuyperTo me, execution of the compound statement is what I want to have
happen.
The question under discussion is about what the C standard says,
not about what anyone wants or expects. Everyone, or at least
every C programmer, expects and wants a function body to be
executed when a function call expression is evaluated - there is
no disagreement about that.
Post by James KuyperIt may be a failure of my imagination, but I can't imagine what it
would mean for that to happen without transferring control, but if
it could, I also can't imagine caring.
If you get to a point where a conversation doesn't make sense, you
might want to go back and take another look at earlier comments,
to see if there is a point where assumptions on the two sides
diverged, either because someone didn't understand what the other
party was saying or because what someone was trying to say wasn't
said very well and may have been misinterpreted. If that has
happened it's unlikely any progress will be made until the
divergence has been identified and somehow reconciled.