lint vs varargs

John C. Lusth jcl at bdrc.UUCP
Thu Oct 26 04:35:18 AEST 1989


I have a lint question. Why does lint complain about varargs stuff?

For example:

 1:	#include <stdio.h>
 2:	#include <varargs.h>
 3:	
 4:	main ()
 5:	
 6:	{
 7:		(void) error ("hello world, says %s\n", "john");
 8:	}
 9:	
10:	error (va_alist)
11:	
12:	va_dcl
13:	
14:	{
15:		va_list ap;
16:		char *format;
17:	
18:		va_start(ap);
19:		format = va_arg(ap, char *);
20:		(void) vprintf (format, ap);
21:		va_end();
22:
23:		return 0;
24:	}

Plain old lint yields:

    test.c(19): warning: possible pointer alignment problem

Linting this beastie with the -c option yields:

    test.c(18): warning: illegal pointer combination
    test.c(19): warning: illegal pointer combination
    test.c(19): warning: possible pointer alignment problem

I'm using a SUN 4, Sun OS 4.0.3. I understand (sorta) the complaint on
line 18, which I think, after macro expansion, casts a pointer to int
to a pointer to char. On a system where int * is bigger than char *
(are there any?), this would fail.  On second thought, however, I just
remembered that (pre-ANSI) char * is guaranteed to be the generic
pointer (i.e. at least as wide as any other pointer).

On line 19, we get a cast of a char * to a char **. No guarantee that
char ** is as wide as char *, so I guess the complaint, while annoying,
is valid.

Would someone explain line 18 to me (and 19 if my reasoning is wrong)?
..and give me a hint on how to shut lint up?

-- 
John C. Lusth, Becton Dickinson Research Center, RTP, NC, bdrc!jcl at mcnc



More information about the Comp.lang.c mailing list