On Tue, Oct 18, 2011 at 2:25 PM, Nadav Har'El <n...@math.technion.ac.il> wrote:
> On Tue, Oct 18, 2011, Elazar Leibovich wrote about "Re: Newer gcc swallow 
> version control keywords":
>> fileversion.h:
>> class FileVersion {FileVersion(const string& v){__files.push_back(v);}};
>>
>> foo.cc:
>> static const FileVersion foo("$id$");
>
> Well, basically you're showing that unlike C where a static constant that
> is never used can be optimized out, in C++ even a static constant that is
> never used can NOT, and therefore will not, be optimized out, because its
> constructor could have any unknown side-effects (in your example, writing
> to a global vector). This is interesting.

No, no, it is optimized out - Elazar tried to make a global non-static
(non-file-scope) variable (non-constant) that *is* used (by the main()
routine - and may be used, including modification, by anyone else.
Apart from that the only difference between C and C++ is that in C++
you can write a relatively simple constructor code (while dragging
stuff like <vector< and <string> and possibly <algorithm> in) that
will insert a reference into a global container.

-- 
Oleg Goldshmidt | p...@goldshmidt.org

_______________________________________________
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il

Reply via email to