By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

Inlined Function still a function call w.r.t. Sequence points?

P: n/a
joe
Consider the following program:

include <iostream>

class Bar
{ public:
int getData9() { m_data = 9; return m_data;}
int getData11() { m_data = 11; return m_data;}

int m_data;
};

int main()
{
Bar f;
int a = f.getData11() f.getData9();

std::cout<<"Answer: "<<a<<std::endl;
}

This program on this (not so great in general) compiler produces an
answer of "0".

My assumption is that each of the function calls should be a sequence
point, and the behavior according to the standard is well defined.
The fact that these function calls happen to be inlined by the
compiler (something a caller has no control over) does not change the
fact that they are indeed "function calls" with regards to what is and
what is not a sequence point.

Any thoughts? References?

Thanks
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 22 Maj, 23:21, joe <joeyc...@mail.comwrote:
Consider the following program:

include <iostream>

class Bar
{ public:
* int getData9() * { *m_data = 9; *return m_data;}
* int getData11() { *m_data = 11; return m_data;}

* int m_data;

};

int main()
{
* Bar f;
* int a *= f.getData11() f.getData9();

* std::cout<<"Answer: "<<a<<std::endl;

}

This program on this (not so great in general) compiler produces an
answer of "0".

My assumption is that each of the function calls should be a sequence
point, and the behavior according to the standard is well defined.
The fact that these function calls happen to be inlined by the
compiler (something a caller has no control over) does not change the
fact that they are indeed "function calls" with regards to what is and
what is not a sequence point.

Any thoughts? *References?

Thanks
Your compiler is wrong. There is a sequence point after each function
call:

[program.execution]
"When calling a function (whether or not the function is inline),
there is a sequence point after the evaluation of all function
arguments (if any) which takes place before execution of any
expressions or statements in the function body."

/Peter
Jun 27 '08 #2

P: n/a
On May 22, 4:21*pm, joe <joeyc...@mail.comwrote:
Consider the following program:

include <iostream>

class Bar
{ public:
* int getData9() * { *m_data = 9; *return m_data;}
* int getData11() { *m_data = 11; return m_data;}

* int m_data;

};

int main()
{
* Bar f;
* int a *= f.getData11() f.getData9();

* std::cout<<"Answer: "<<a<<std::endl;

}

This program on this (not so great in general) compiler produces an
answer of "0".

My assumption is that each of the function calls should be a sequence
point, and the behavior according to the standard is well defined.
The fact that these function calls happen to be inlined by the
compiler (something a caller has no control over) does not change the
fact that they are indeed "function calls" with regards to what is and
what is not a sequence point.

Several issues:

- The result should be 2, not 0.

- The function being inlined has no impact on sequence points

- As written, there's nothing that would be impacted by sequence
points anyway.
Jun 27 '08 #3

P: n/a
joe
Thanks for all the responses. That's what I believed.

The assembler output produced is ... amusing

bl _main
li r12, 9 // Load value "9" into register 12
li r12, 11 // Load value "11" into register 12 ??
subf r12, r12, r12 // Subtract r12 by r12 and store in r12
-
Joe
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.