Go to the first, previous, next, last section, table of contents.

## Using keywords

To include a keyword string you simply include the relevant text string, such as `$Id$`, inside the file, and commit the file. CVS will automatically expand the string as part of the commit operation.

It is common to embed `$`Id$ string in the C source code. This example shows the first few lines of a typical file, after keyword substitution has been performed:

    static char *rcsid="$Id: samp.c,v 1.5 1993/10/19 14:57:32 ceder Exp $";
    /* The following lines will prevent gcc version 2.x
       from issuing an "unused variable" warning. */
    #if __GNUC__ == 2
    #define USE(var) static void * use_##var = (&use_##var, (void *) &var)
    USE (rcsid);
    #endif

Even though a clever optimizing compiler could remove the unused variable `rcsid`, most compilers tend to include the string in the binary. Some compilers have a `#pragma` directive to include literal text in the binary.

The `ident` command (which is part of the RCS package) can be used to extract keywords and their values from a file. This can be handy for text files, but it is even more useful for extracting keywords from binary files.

    $ ident samp.c
    samp.c:
         $Id: samp.c,v 1.5 1993/10/19 14:57:32 ceder Exp $
    $ gcc samp.c
    $ ident a.out
    a.out:
         $Id: samp.c,v 1.5 1993/10/19 14:57:32 ceder Exp $

SCCS is another popular revision control system. It has a command, `what`, which is very similar to `ident` and used for the same purpose. Many sites without RCS have SCCS. Since `what` looks for the character sequence `@(#)` it is easy to include keywords that are detected by either command. Simply prefix the RCS keyword with the magic SCCS phrase, like this:

    static char *id="@(#) $Id: ab.c,v 1.5 1993/10/19 14:57:32 ceder Exp $";

Go to the first, previous, next, last section, table of contents.