<div dir="ltr"><div class="gmail_quote">On Tue, Oct 18, 2011 at 11:50 AM, Nadav Har'El <span dir="ltr"><<a href="mailto:nyh@math.technion.ac.il">nyh@math.technion.ac.il</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
On Tue, Oct 18, <a href="tel:2011" value="+9722011">2011</a>, Elazar Leibovich wrote about "Re: Newer gcc swallow version control keywords":<br>
<div class="im">> Excuse the idiotic solution, but can't you just add an option to print it<br>
> out?<br>
><br>
> int main(int argc,char**argv) {if (argc == 2 && strcmp(argv[1],"--ident")<br>
> puts(ident);...}<br>
<br>
</div>The point in Oleg's trick (which is not Oleg's invention - it has been in<br>
use for decades) is to be able to tell not just a single version number for<br>
the executable (your "--ident" is basically the same as "--version" supported<br>
by many programs), but rather to be able to tell the exact version of each<br>
and every source code file which participated in creating this executable.<br>
You run "ident" on the executable, and get a list of dozens (or thousands)<br>
of source file names and their exact version numbers and dates. This could<br>
be useful if you have a lot of versions of your code running around, and<br>
you don't remember how exactly each executable was generated.<br></blockquote><div><br></div><div>I didn't understand that, but anyhow. Same idea could apply.</div><div><br></div><div>For C++:</div><div>main.cc:</div>
<div>vector<string> __files;</div><div>int main(int argc,char**argv) {if (argc == 2 && string(argv)=="--ident") {for (auto file:__files) cout << file << "\n";exit(0);}}</div><div>
<br></div><div>fileversion.h:</div><div>class FileVersion {FileVersion(const string& v){__files.push_back(v);}};</div><div><br></div><div>foo.cc:</div><div>static const FileVersion foo("$id$");</div><div><br>
</div><div>With some macro trickery you might be able to get .init-like behaviour for C. (If you're willing to preprocess the C files with another utility, like you do to replace the $Id$ strings, it's actually not hard at all).</div>
<div><br></div><div>This way, it's not ad-hoc, but a documented working way to get whatever you want in the executable.</div><div><br></div><div>(I perfectly agree with you that today it's less relevant, but I'm taking Oleg's stance for the sake of the discussion)</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br><div class="im"><br>
> It seems like a good idea anyhow, to have a stable way of extracting this<br>
> ident string from the executable (what happens for instance if by accident<br>
> you have rcsident and rcs_ident? How would you know from the stripped<br>
> executable which one to trust?).<br>
<br>
</div>The idea with ident(1) is that the content of the string, not the variable<br>
name holding it, has a recognizeable structure. In particular, it looks like<br>
this: $Id: something $ - with the word "something" replaced by anything you<br>
wish. ident(1) looks for such strings in any file you give it - whether it<br>
is an executable, source code, or whatever, and prints them.<br></blockquote><div><br></div><div>I understood that, and it's still unstable. Since if some young team member not aware of the $Id: trick, will write:</div>
<div> log("$Id: %d $Name: %s\n",id,name)</div><div>ident will return garbage.</div><div>If you have documented way to get the ident strings, it's more stable.</div><div><br></div></div></div>