Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA
Path: utzoo!watmath!clyde!burl!ulysses!allegra!bellcore!decvax!genrad!mit-eddie!godot!harvard!seismo!brl-tgr!tgr!lcc.gm@UCLA-LOCUS.ARPA
From: Greg McGary 
Newsgroups: net.unix-wizards
Subject: Keeping flags and flag-words consistent
Message-ID: <7240@brl-tgr.ARPA>
Date: Fri, 11-Jan-85 20:03:45 EST
Article-I.D.: brl-tgr.7240
Posted: Fri Jan 11 20:03:45 1985
Date-Received: Tue, 15-Jan-85 00:43:55 EST
Sender: news@brl-tgr.ARPA
Organization: Ballistic Research Lab
Lines: 45

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@ucla-cs
	 {ihnpr,randvax,sdcrdcf,ucbvax}!ucla-cs!lcc!gm
		{trwspp,ucivax}!ucla-va!ucla-cs!lcc!gm
					   trwb!lcc!gm