Newer gcc swallow version control keywords
Nadav Har'El
nyh at math.technion.ac.il
Tue Oct 18 14:25:54 IST 2011
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. But Oleg's question was about C,
and unfortunately he showed that in his case, the compiler does optimize
his constants out (if he uses -O2).
> 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).
>
> This way, it's not ad-hoc, but a documented working way to get whatever you
> want in the executable.
What are you talking about, "#ident"? Indeed, it's not ad-hoc and has existed
for ages. But Oleg noted that it's not part of the C standard, and indeed I
checked and it isn't. But it's still possible that all common compilers
nowadays support it. Definitely all versions of gcc support it.
> I understood that, and it's still unstable. Since if some young team member
> not aware of the $Id: trick, will write:
> log("$Id: %d $Name: %s\n",id,name)
> ident will return garbage.
> If you have documented way to get the ident strings, it's more stable.
The idea of the "$Id: " (RCS) or "@(#) " (SCCS) prefixes is that nobody
can accidentally write them by mistake. Why would a young team member use
it incorrectly? Either you would use it (in which case you know what you're
doing) or you won't. Typically coding conventions will specify that you use
it - correctly - on every source file.
--
Nadav Har'El | Tuesday, Oct 18 2011,
nyh at math.technion.ac.il |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |Vote, n.: A person's right to make a fool
http://nadav.harel.org.il |of himself and a wreck of his country.
More information about the Linux-il
mailing list