Aucbvax.2275
fa.unix-wizards
utzoo!duke!decvax!ucbvax!saks@LL-XN
Tue Jul 14 11:41:47 1981
lint and enumerated types
From: Joft Saks <SAKS@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);
       }




-----------------------------------------------------------------
gopher://quux.org/ conversion by John Goerzen <[email protected]>
of http://communication.ucsd.edu/A-News/


This Usenet Oldnews Archive
article may be copied and distributed freely, provided:

1. There is no money collected for the text(s) of the articles.

2. The following notice remains appended to each copy:

The Usenet Oldnews Archive: Compilation Copyright (C) 1981, 1996
Bruce Jones, Henry Spencer, David Wiseman.