Inlining is safe, even with static variables.
The C++ standard defines the "inline" keyword as a hint without any
semantic meaning. The compiler may decide about inlining a function
independent of whether the keyword is given. I do not even know whether
the keyword has any influence at all in modern compilers.
As Joris states, the code that Massimiliano suggests is basically what
the compiler produces internally from my last solution. (except that I
did not reuse the variable between the two functions)
Greetings,
Norbert
Joris van der Hoeven wrote:
On Sun, Jun 14, 2009 at 06:36:56PM +0200, Gubinelli Massimiliano wrote:
Hi Norbert,
I'm not sure about the behaviour of static variables in inline
functions. What about the following code?
extern url url_none_constant;
inline url url_none () { if (is_nil(url_none_constant))
url_none_constant = as_url (tree("none")); return url_none_constant; }
inline bool is_none (url u) { return u->t == url_none()->t; }
I think that this is the kind of code generated by the compiler.
A boolean is used for indicating whether the static variable is used for
the first time. This probably remains correct for inline routines,
but it is true that I am not sure.
I will implement something else.
Best wishes, Joris
_______________________________________________
Texmacs-dev mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/texmacs-dev
_______________________________________________
Texmacs-dev mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/texmacs-dev