Checking # of parms

Conor P. Cahill cpcahil at virtech.uucp
Thu Dec 21 11:59:11 AEST 1989


In article <339 at cerc.wvu.wvnet.edu.edu>, tad at cathedral.cerc.wvu.wvnet.edu (Tad Alan Davis) writes:
> 
> Is there a quick & dirty way, using grep, awk, or some such filter to check
> the number of parmeters of a function.  Basically, I have a large set of 
> functions which I call frequently with the wrong number of parms.  I want to
> put the names of the functions and the number of parms in a file and use a
> filter to check them in a C program.

why not just use cpp.

> 
> For example	File	
> 			funcX 2
> 
> 		Command	
> 			grep funcX prog.c | grep -v funcX([^,]*,[^,]*)

		File

			funcX 2

		Commands:
			echo "#define funcX(a,b) never_used_name1(a,b)" > t$$.c
			cat prog.c > t$$.c
			cc -P t$$.c

			/* you will get an argument mismatch message for 
			   each incorrect usage.  You only have to adjust for 
			   the extra #defines you added to the beginning
			   of the file.


This will work for all the examples you gave.
If you are really worried about this as an ongoing problem, you might
want to put the following into an include file:

	#ifdef CHECK_FUNC_ARGS
	#define funcX(a,b) never_used_name1(a,b)"
	#define funcY(a,b,c) never_used_name2(a,b)"
	.
	.
	.
	#endif

and include it in your modules.  That way you could just add a
-DCHECK_FUNC_ARGS to the compile line whenever you wanted to check
the argument counts.  

I wouldn't use the module compiled with this flag turned on because it
will make debugging real hard, since the linker will see the 
function names "never_used_name1, etc" and not funcX/funcY.

Good luck


-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.unix.questions mailing list