Re: inline function
On Jul 31, 1:51 am, jg <jgu...@gmail.com> wrote:
Does C++ standard require an inline function be generated all the
time ?
For example,
#include <iostream>
using namespace std;
inline int foo()
{
return 10;
}
int main()
{
cout << "foo()=" << foo() << endl;
}
Should foo() be generated in the final executable all the time ?
I'm not sure what you mean by "generated". The language defines
the semantics of a given C++ program (provided there is no
undefined behavior). Those semantics result in one or more
possible "observable behavior". Basically, the language
standard then says that a compiler can do whatever it wants, as
long as executing the resulting program results in one of the
observable behaviors.
On a Unix, machine, for example, for the above a compiler could
legally generate something like:
write( 1, "foo()=10\n", 9 ) ;
return 0 ;
Most compilers will probably generate something like:
cout << "foo()=" << 10 << endl ;
return 0 ;
for the above.
Some compilers might also generate an out of line copy of foo(),
perhaps to simplify debugging (e.g. if you've asked for
debugging information). What the compiler generates, however,
doesn't matter as long as executing the code results in an
observable behavior which corresponds to the specified
semantics.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34