Linting a routine using varargs (WidgetSet())

Marc Ries ries at arcturus
Sat Feb 25 08:46:02 AEST 1989


   Ok.  Flame me, beat me, make me write bad code!   8-)

   I have an X program that is using the recently posted
   utility function called "WidgetSet".  I can't get lint
   to shut up about things like:
==========   
WidgetSet: variable # of args.	myprog.c(433)  ::  myprog.c(532)
    431         	      DwtNadbLeftAttachment, DwtAttachWidget,
    432         	      DwtNadbLeftWidget, namelabel,
    433 >>>     	      DwtNadbRightAttachment, DwtAttachAdb, NULL);
    530         	      DwtNadbLeftAttachment, DwtAttachAdb,
    531         	      DwtNadbBottomAttachment, DwtAttachAdb,
    532 >>>     	      DwtNadbRightAttachment, DwtAttachAdb, NULL);

WidgetSet, arg. 3 used inconsistently	myprog.c(433)  ::  myprog.c(532)
    431         	      DwtNadbLeftAttachment, DwtAttachWidget,
    432         	      DwtNadbLeftWidget, namelabel,
    433 >>>     	      DwtNadbRightAttachment, DwtAttachAdb, NULL);
    530         	      DwtNadbLeftAttachment, DwtAttachAdb,
    531         	      DwtNadbBottomAttachment, DwtAttachAdb,
    532 >>>     	      DwtNadbRightAttachment, DwtAttachAdb, NULL);

WidgetSet, arg. 5 used inconsistently	myprog.c(433)  ::  myprog.c(532)
    ...
==========   
   The actual WidgetSet function looks like this:
==========   
/*VARARGS*/
void
WidgetSet(va_alist)
va_dcl
{
    String   argstr;
    Arg      args[MAXARGS];
    XtArgVal argval;
    int      i = 0;
    va_list  var;
    Widget   w;

    va_start(var);

    w = va_arg(var, Widget);

    while (argstr = va_arg(var, char *)) {
	if (i == MAXARGS) {
	    fprintf(stderr, "Warning: increase MAXARGS! (%d)\n", i);
	    XtSetValues(w, args, i);
	    i = 0;
	}
	if (!strcmp(argstr, XtNargList)) {
	    ArgList list = va_arg(var, ArgList);
	    XtArgVal numargs = va_arg(var, Cardinal);
	    XtSetValues(w, list, numargs);
	} else {
	    argval = va_arg(var, XtArgVal);
	    XtSetArg(args[i], argstr, argval);
	    ++i;
	}
    }
    va_end(var);
    if (i > 0)
	XtSetValues(w, args, i);
}
==========   

   I've gone thru a bunch of old NETNEWS programs that use
   functions created with VARARGS, and even RTFM on things
   like vprintf(), but still don't see the light.
   I understand why lint is complaining, and I know that the
   program runs fine as is.
   Is a dummy version of WidgetSet needed withing my program?
   Is there a solution?  Thanks for any pointers.
 
   
Marc Ries
TRW Defense Systems Group/HMI
UUCP: ...!spp2!ries at trwspp.UUCP



More information about the Comp.lang.c mailing list