tags:

views:

38

answers:

3
/* $Id: file.c,v 1.0 2010/09/15 01:12:10 username Exp $ */

I find this line in many source code files in the comment at the top (header) of the file. Why? Is it aimed for the version control software? -Thanks.

+2  A: 

These sort of comments are automatically modified by various source code control systems, things like author, date, history and so forth.

See here for some common ones for RCS which is the first source code control system I every saw to implement it (that doesn't mean it was the first, just that RCS was the first I ever used and it had that capability).

One particular trick we used to use was to put the line:

static char *fileId = "$Id: $";

into the source file (and header files as well, although the names had to be unique) so that, when it was built, it would automatically have the ID of the files in the executable itself.

Then we could use something like strings to find out which source files were used to build the executable. Ideal for debugging problems in the field.

paxdiablo
I like the fileId trick. Out of curiosity, can you get the same information from gcc -g (or other compilers w/ debug options)?
M.S.
No idea. I wouldn't think so since gcc doesn't really have source control built into it. But I wouldn't put it past them to try :-) You can usually get the filename with most compilers by using the predefined macro `__FILE__` but version information is another level.
paxdiablo
+1  A: 

It tells CVS (and other VCSs) to expand the value of the Id at check-out time, so anybody reading the source file in question will know what version exactly was checked out for it. Not very popular any more (you can always ask your VCS for such info if you keep the source file in a client / repository / working directory -- or however else your VCS calls such things;-).

Alex Martelli
+1  A: 

I believe you are correct. It appears to be a keyword substitution string for CVS. Take a look at this question http://stackoverflow.com/questions/346301/id-name-of-file-date-time-creation-exp

HTH Steve

Steve Robillard