This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PCH, and more generally C++ parser performance


>>>>> "Zack" == Zack Weinberg <zack@wolery.cumb.org> writes:

    Zack> Hm.  Is int S<T>::i the same variable as the static int i
    Zack> inside the declaration of struct S?  If so then I think I
    Zack> get it: this expression provides the initializer for that
    Zack> variable.  But it still might not be used, because we
    Zack> haven't said what T is yet.

Right.

    Zack> Even if there are no such weasel words, couldn't we arrange
    Zack> to call f and throw the value away?

I don't think there are any such weasel words -- but I could be
wrong.

Yes, we could call `f' and throw the value away -- but how would we
know to do that without parsing `g'?

    Zack> If I write two normal functions, one of which refers to
    Zack> S<int> and the other S<double>, is f called twice?

Yes.

    Zack> If your example is in a header file and two files include
    Zack> it, how do we avoid initializing S<int>::i twice (hence
    Zack> calling f twice)?

Magic.  Each static template variable has an associated guard
variable; the initialization code checks that the guard variable is
not set before performing the initialization.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]