Operating System - Linux
1827707 Members
2822 Online
109967 Solutions
New Discussion

Source code header question

 
SOLVED
Go to solution
Fei Rao
Advisor

Source code header question

Many source code files have something like the following statement at the beginning:

#ifndef lint
static char ModuleId[] = "@(#)FTAM: ftm_conn.c $Revision: 9.1 $ $Date: 94/11/17 17:36:21 $";
#endif

What does this mean? It looks strange. And the time was so accurate. Is this generated by some program?
Please help!

Thanks in advance.
Fei
Life is easy. Life is hard.
8 REPLIES 8
Arunvijai_4
Honored Contributor

Re: Source code header question

This is generated by lint or splint, Splint is a tool for statically checking C programs for security vulnerabilities and coding mistakes. With minimal effort, Splint can be used as a better lint. If additional effort is invested adding annotations to programs, Splint can perform stronger checking than can be done by any standard lint.

If you want for HP-UX 11i, download from
http://hpux.connect.org.uk/hppd/hpux/Development/Tools/lclint-2.5q/
http://www.splint.org/

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Fei Rao
Advisor

Re: Source code header question

Can this tool be used to check programs in C++? and the string written by human or generated automatically? I have no idea about it.
Life is easy. Life is hard.
Arunvijai_4
Honored Contributor

Re: Source code header question

Yes, You can use for C++ programs. Strings are generated by the program itself.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Fei Rao
Advisor

Re: Source code header question

Could you give me a simple example? My MSN is: fera_bill@hotmail.com. Welcome to be my friend!

Thanks
Life is easy. Life is hard.
Matti_Kurkela
Honored Contributor
Solution

Re: Source code header question

I think Arunvijai's explanation was not entirely correct.

The construction "#ifndef lint" ... "#endif" means that the lines between them are excluded when a macro named "lint" is defined.

Source code analyzers like lint and splint define that macro to allow the programmer to exclude things that would confuse the analyzer program and produce useless error messages.

The "static char ModuleId[] = ..." line looks like it contains automatic version numbering directives. These are used when the source code is stored in an automated version control system, like RCS, CVS, Subversion, BitKeeper and others. When this kind of software is used, it is often said that the source code is in a "repository".

The programmer writes just the "$Revision: $" and "$Date: $" parts. The revision control system automatically increments the version numbers and updates the date/time values each time the programmer stores a changed version of the file into the repository. This is often called a "commit".

Because the string is declared as a static one-dimensional table of characters (a string in C programming language), this string gets included in the compiled program, even if it is not actually used anywhere in the program code.

When a program is being tested, the testers may need to know which exact version of each source code file was used in compiling the program. This is just a way to embed the information in the program binary.

You can check it out yourself: on most unix-like operating systems you can try to extract all the readable strings from a program binary using the "strings" command.
For example, on HP-UX 11.11 I can enter the command:

strings /bin/ls |more

The first line contains a text that looks familiar:
$Revision: 92453-07 linker linker crt0.o B.11.16 000601 $

Because it mentions "linker" and "crt0.o" I believe this tells us the version of the C compiler used in producing the "ls" command.

On HP-UX, you might need the "-a" option to get all the strings in the program:

strings -a /bin/ls |more

Now you get (among other things) something like this:
ls.c $Date: 2003/03/13 02:04:47 $Revision: r11.11/2 PATCH_11.11 (PHCO_27415)
$Revision: @(#) all CUP11.11_BL2003_0504_1 PATCH_11.11 PHCO_27415\n @(#) Sun May 4 22:44:52 PDT 2003 $

This describes the exact version of "ls" command source code, if someone ever needs to know.
MK
Fei Rao
Advisor

Re: Source code header question

Oh, I think I can understand that now.
Thank you.

Fei
Life is easy. Life is hard.
Daavid Turnbull
Frequent Advisor

Re: Source code header question

In understanding the options here you may wish to look at the man pages for "ident" and "what" as tools for extracting version strings from binaries and scripts.

Tools like cvs can be used to automatically update version strings in source file. For scripts you can just have the $Header entry in comments but if you want the header to to persisist into binaries and executables it needs to be a statically defined string so it does not get stripped out.

Here is a string that has been inserted by cvs into a Perl script:

# "$Header: /opt/cvs/CCT/scripts/sendMime.pl,v 1.1 2005/10/26 05:19:58 daavid Exp $";

In some of my make files I have them append a line to a source file which is the name of the final compiled binary, so that it will always be updated in the cvs repository. The only "source" in this file is the statically defined string. This automatically maintains the version number for the binary every time the code is updated in cvs. A combination of ident and grep quickly and reliably allows this version number to be extracted. eg (this binary is called "legacy"):

> ident legacy | grep legacy
legacy:
$Header: /opt/cvs/CCT/servers/legacy/legacy.cpp,v 1.38 2005/05/24 03:12:38 daavid Exp $
Behold the turtle for he makes not progress unless he pokes his head out.
Fei Rao
Advisor

Re: Source code header question

Got the idea.
Life is easy. Life is hard.