ARM Technical Support Knowledge Articles

DOES ENUM TYPE CHECKING WORK?

Applies to: C51 C Compiler

Answer

QUESTION

I use a lot of enums in my C code. Does the C compiler perform type checking for enums to validate? I need to know that I'm using correct enums for certain variables. For example:

enum apple { MAC, GRANNY, WASH_ST };
enum pear { GREEN, BROWN, BARTLETT };

static void func(enum apple a, enum pear p);

func (BARTLETT, MAC);

The above code generates no warnings when BARTLETT is passed for the enum apple parameter. Is this correct?

ANSWER

Yes. This is correct. Currently, C51 does not perform type checking for enumerations. This feature will be added in a future release of C51.

PC-Lint performs this type of error checking and it can easily be integrated into the uVision IDE.

Article last edited on: 2004-06-07 11:09:26

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential