This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Prohibit enum <-> int mixup
* Enrico Weigelt <weigelt@metux.de> wrote:
<snip>
To make it more clear what I'm trying to do:
The current codebase uses enums eg. for declaring several options
(eg. selectable values or choosable actions in some GUI). The
application often is contigiously adapted for each job/project.
For example, the supported languages of are configured in the
source like that:
enum LANGUAGES
{
LANGUAGE_NONE = 0,
LANGUAGE_GERMAN,
LANGUAGE_ENGLISH,
LANGUAGE_FRENCH,
LANGUAGE_MAX,
LANGUAGE_ITALIAN
...
};
The funny thing: LANGUAGE_MAX tells the maximum of supported
languages in the current configuration (when some change, they
get reordered above or under the LANGUAGE_MAX), and several
places iterate or check for the range of
LANGUAGE_NONE < x < LANGUAGE_MAX.
Even worse: sometimes numeric values are used instead of the
enum values, which will cause a hell of trouble when the enums
change. (eg. for return codes, etc).
Obviously this is crappy, and I'd like to clean that up step
by step. We have *lots* of such stuff lying around anywhere
in the app.
If I could tell the compiler to simply forbid such mixups,
that would be *great* help for identifying such places.
cu
--
----------------------------------------------------------------------
Enrico Weigelt, metux IT service -- http://www.metux.de/
phone: +49 36207 519931 email: weigelt@metux.de
mobile: +49 151 27565287 icq: 210169427 skype: nekrad666
----------------------------------------------------------------------
Embedded-Linux / Portierung / Opensource-QM / Verteilte Systeme
----------------------------------------------------------------------