ado@elsie.UUCP (03/03/84)
Apologies if this is rehash...
One way to get "Source Code Control System*" strings into the object file for
"file.c" is to have it include a line like
static char sccsid[] = "%A%";
However, if I include this line and fail to refer to sccsid, lint gripes.
I can get the SCCS information in (and keep lint happy) with a line like
static sccsid() { if (!"%A%") sccsid(); }
which I think is pretty obscure.
(Briefly: the call of sccsid avoids a lint "defined but never used" diagnostic;
"%A%" appears in an "if" expression to avoid a lint "null effect" diagnostic;
the '!' is there to avoid an infinite loop if "sccsid" is mistakenly called,
and to reduces the amount of code generated.)
What's a clearer or more concise way of doing this?
Use the 'r' command to reply to me by mail if you know. Thanks.
--
* Unless "SCCS" is a trademark, I'm trademark free for once.
--
UUCP: decvax!harpo!seismo!rlgvax!cvl!elsie!ado
DDD: (301) 496-5688rjk@mgweed.UUCP (Randy King) (03/05/84)
I have used the following to shut up lint and include data space
declarations of the SCCS keywords:
#define SCCSID(x) atoi(x)
main()
{
SCCSID("%A% %M%");
.
.
}
Note that this does take some process time; keep it out of recursive
calls. I looked for the most harmless of functions for this task
and atoi seemed to fit the bill.
Randy King
AT&T/CP-MG
ihnp4!mgweed!rjkguy@rlgvax.UUCP (Guy Harris) (03/06/84)
The clean way to solve the problem is:
#ifndef lint
static char sccsid[] = "...";
#endif
This works on systems using the BTL implementation of "lint", at least on
4.xBSD and System III and later versions, because the initial list of
parameters passed to "cpp" from the "/usr/bin/lint" shell file is:
O="-C -Dlint" X= P=unix #default parameters
So "lint" is predefined when something is passed through "lint". This trick
is used quite a bit in Berkeley code.
Guy Harris
{seismo,ihnp4,allegra}!rlgvax!guydave@qtlon.UUCP (Dave Lukes) (03/11/84)
What's wrong with:
main() {
"%W% %G% or whatever ??";
}
or, if you prefer:
main() {
(void)"%W% %G% or whatever ??";
}
Yes, it IS legal C, just like:
main() {
3;
}
(Check the reference manual: ANY expression is a valid statement !)
Yours sardonically,
Dave Lukes (<U.K>!ukc!qtlon!dave)