This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
C enum type warning
- From: Federico Ruiz <memeruiz at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 30 Jun 2009 01:00:13 +0200
- Subject: 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