This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C enum type warning


Hi all,

(sorry to send this email again, I pressed an emacs key combination on
gmail by error then the email was sent, and the email was not
complete)
I have been looking for a way to detect a programming error like the
following with gcc:

enum foo_e {
 ZERO,
 ONE,
  TWO
};

int main(void) {
  enum foo_e bar;
  bar=ZERO; // correct use of bar
  bar=50; //possible incorrect use of bar
  ....
}

I couldn't find a way to get a warning message from gcc for the second
use of bar (I tried -Wall and -Wswith-enum). Is there a way to get
warning out of this? I played around with splint and it can detect
this type of programming error, the problem with splint is that only
parses C89 code and it gives for example parse errors for variable
declarations inside of for expresions. Also splint seems to be
unmaintained nowadays.

Thanks and all the best,
Federico Ruiz Ugalde


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]