The purpose of the string "$ Id: ..." in the header of the source files

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

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

+7
coding-style
source share
3 answers

These comments are automatically modified by various source control systems, such as author, date, history, etc.

See here for some common ones for RCS, which is the first source control system I have ever seen to implement this kind of thing (which does not mean that it was the first, just RCS was the first that I ever used , and had such an opportunity).

One specific trick we used was to put a line:

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

to the source file (and header files, although the names must be unique), so when it was created, it will automatically receive the file identifier in the executable file itself.

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

+7
source share

It tells CVS (and other VCS) to expand the Id value during checkout, so anyone reading the source file will know which version was checked for it. Not very popular (you can always ask your VCS for such information if you save the source file in the client / repository / working directory, or, nevertheless, your VCS names such things ;-).)

+3
source share

I think you're right. This seems to be a keyword replacement string for CVS. Take a look at this question $ id: filename, date / time creation Exp $

+2
source share

All Articles