Keeping flags and flag-words consistent

Greg McGary lcc.gm at UCLA-LOCUS.ARPA
Sat Jan 12 11:03:45 AEST 1985


I was recently bitten by a bug that caused me more trouble than it should
have.  By doing a careful audit on the usage of certain flags and flag
words, I discovered that a flag test was and-ing the correct flag with
the wrong flag-word.

Determined to stamp out all bugs of this nature, I need an automated
method of detecting such inconsistencies.  I have a couple of ideas:

1)	Use a C language `enum' type to define the flag values, then
	declare the flag word to be of that type so that the compiler
	and/or lint can detect type clashes.

	The problem with this approach is that I have no control over
	the size of an `enum' variable or structure member.  The C
	Reference Manual says that `enum' variables have the same size
	as `int'.  I consider it evil to use `int' in structures-- one
	should use `char', `short', or `long' since their size is quite
	a bit less fuzzy.

2)	Build a shell program using grep to audit the uses of a given
	flag or flag-word.

	The disadvantage here is that it is difficult to lexically
	isolate expressions and thereby identify a flag/flag-word pair.

3)	Build a syntax directed source analyzer to detect expressions
	and audit flag/flag-word usage.

	The disadvantages here are economic.  It's just too damn much
	work to build such a special purpose beast.  Especially when
	you consider that cpp manifest constants must remain un-expanded
	for the thing to work at all.


Has anyone out there thought about this problem, and hopefully built
a tool to check for this type of error??

Please reply by mail.  I'll summarize later.  Thanx,

			Greg McGary
			Locus Computing Corp.
						lcc!gm at ucla-cs
	 {ihnpr,randvax,sdcrdcf,ucbvax}!ucla-cs!lcc!gm
		{trwspp,ucivax}!ucla-va!ucla-cs!lcc!gm
					   trwb!lcc!gm



More information about the Comp.unix.wizards mailing list