lint and enumerated types

utzoo!duke!decvax!ucbvax!saks at LL-XN utzoo!duke!decvax!ucbvax!saks at LL-XN
Tue Jul 14 11:41:47 AEST 1981


From: Joft Saks <saks at LL-XN>
For some reason or another, our lint does not seem to like some things about
enumerated types.  I have included below two (unrelated) C-source files which
use enumerated types.

Note that in the first, I have used the feature which allows one to set a
particular value in the enum - list.  (Let's forget for a moment any qualms
we may have about said feature.)  Applications of lint to this program yield
the following message:

	"puterr.c", line 35: warning: nonportable character comparison

Applications of lint to the second program yield the message:

	stuff value used inconsistently "test.c"(12)  ::  "test.c"(20)

Ken Schroder (schroder at ll-asg) thinks older versions of lint may have trouble
with functions which return enumerated types.  If anyone else has encountered
troubles, or has some ideas/suggestions/comments/anything at all useful to say
about this, please let me know.  Many thanks.

--------------------------------------------------------------------------------

puterr.c
--------
/*
 * print an error message
 */
#include <stdio.h>
typedef enum
	{
	ERRNONE = -1,
	ERRNOTFOUND,
	ERRNOTPLAIN,
	ERRDIRACC,
	ERRNAMELONG,
	ERRREADACC,
	ERRWRITEACC,
	ERRCHNGSACC,
	ERRDIFFEXEC
	}
	tpserror;

tpserror puterr(e, progname, s)
	tpserror e;
	char *progname, *s;
	{
	static char *format[] =
		{
		"%s: can't find %s\n",
		"%s: %s is special file or directory\n",
		"%s: can't access containing directory %s\n",
		"%s: file name too long %s\n",
		"%s: no read privileges on %s\n",
		"%s: no write privileges on %s\n",
		"%s: can't access changes file for %s\n",
		"%s: can't execute 'diff' for %s\n"
		};

	if (e != ERRNONE)
		fprintf(stderr, format[(int)e], progname, s);
	return (e);
	}


--------------------------------------------------------------------------------


test.c:
-------

#include <stdio.h>

typedef enum
	{
	RED,
	GREEN,
	BLUE
	}
	color;

color stuff()
	{

	return (RED);
	}

main()
	{

	if (stuff() == RED)
		fprintf(stderr, "stuff == RED\n");
	else
		fprintf(stderr, "stuff != RED\n");
	exit(0);
	}






More information about the Comp.unix.wizards mailing list