J
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
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