8
/* $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.

  • I'd worry about your system clock if you copied that time string out of an actual file! It us unusual (but not impossible) to create version 1.0, too. – Jonathan Leffler May 04 '10 at 05:53
  • No, it's not any machine. I've just filled in some foobar data, –  May 04 '10 at 05:56

3 Answers3

8

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 ever saw to implement this sort of thing (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.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • I like the fileId trick. Out of curiosity, can you get the same information from gcc -g (or other compilers w/ debug options)? –  May 04 '10 at 06:02
  • 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 May 04 '10 at 07:02
4

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
  • 854,459
  • 170
  • 1,222
  • 1,395
2

I believe you are correct. It appears to be a keyword substitution string for CVS. Take a look at this question $id: name of file, date/time creation Exp $

Community
  • 1
  • 1
Steve Robillard
  • 13,445
  • 3
  • 36
  • 32