<div dir="ltr"><br><br><div class="gmail_quote">On Tue, Oct 18, <a href="tel:2011" value="+9722011" target="_blank">2011</a> at 1:50 PM, Oleg Goldshmidt <span dir="ltr"><<a href="mailto:pub@goldshmidt.org" target="_blank">pub@goldshmidt.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>> I didn't understand how, eg, my C++ scheme don't work. I think it should</div><div>
> work even if you're including the $Id$ strings in the headers files.<br>
<br>
</div>Apart from the fact that you assume that main.cc is mine (what if my<br>
product is a library?),</blockquote><div><br></div><div>There's an important point here.</div><div>If your product is an .so, all you need to do, is to expose the ident objects to the library users (of course, in this case the names of the variables must be unique per file version). This way, the linker is forced to leave those strings intact.</div>
<div><br></div><div>If you're product is an .a archive, well, your out of luck. The same method for so files will work of course for the .a archive, but, the client who links to your program, is free to use a whole program optimizer, which might wipe off your program. I'm not sure it's even possible to mark those strings as "always include" in the object file.</div>
<div><br></div><div>I really recommend this piece[1] by Meyers, who shows that fighting with the optimizer, is doomed to misery.</div><div><br></div><div>[1] PDF: <a href="http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf" target="_blank">http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf</a> Bottom of page 6, Ctrl-F "In essence, you’ve just fired the opening salvo"</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">depends on a whole lot of things I wouldn't<br>
necessarily need for any other purpose, makes the strings global</blockquote><div>Not too global. The global list of strings is exposed only in the main() and in the implementation of the Ident class. If you hate global variables - make it a static variable of the Ident class.</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> and<br>
mutable,</blockquote><div><br></div><div>The list of strings is mutable, right? The stings can be immutable. Also it is possible to use a push-only queue instead of vector. But I'm nitpicking now ;-)</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> and won't pick up, e.g., the case of wrong header I mentioned<br>
before (I checked)?<br></blockquote><div><br></div><div>I don't understand why is that.</div><div>See <a href="https://github.com/elazarl/ident-for-cpp">here</a>[2] for an implementation which Works For Me (TM), with no non-static global variables, and it works for header files.</div>
<div><br></div><div>[2] <a href="https://github.com/elazarl/ident-for-cpp">https://github.com/elazarl/ident-for-cpp</a></div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
This is a good idea in general, but it's not really an improvement.<br>
The trusted old scheme has all the needed properties and if gcc had an<br>
option to disable this particular kind of optimization selectively I<br>
wouldn't have a problem.<br></blockquote><div><br></div><div>If I understood correctly, the problem was how to port the GCC optimization-turn-off to other compilers without macro hackeries. I believe this is a good portable way. I'm trying to find a sane way to do that in portable C, but I'm not sure it's possible without too much effort.</div>
<div><br></div><div>That said, the macro+gcc attribute seems the most reasonable approach given that VS have a way to disable this optimization. However, it spoils all the fun.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<font color="#888888"><br>
--<br>
Oleg Goldshmidt | <a href="mailto:pub@goldshmidt.org" target="_blank">pub@goldshmidt.org</a><br>
</font></blockquote></div><br></div>