ARM Technical Support Knowledge Articles


Applies to: C51 C Compiler


Information in this article applies to:


I have recently tried this code snippet:


typedef enum
   ENQ_IDLE = 0,
} UDE_enq_cmd_state_t;

enum UDE_enq_cmd_state_t {

   ENQ_IDLE = 0,
typedef enum UDE_enq_cmd_state_t EnqCmdState;

UDE_enq_cmd_state_t EnqCmdState;

void main(void)
unsigned char testy;

EnqCmdState = ENQ_IDLE;
EnqCmdState = 15;



and it compiles and links with no errors or warnings.

Normally, I would expect an error on the line: EnqCmdState = 15; otherwise using the typedef is a bit of a waste of time. How do I use this to write more defensive programming?


It is legal in C to assign an 'enum' variable a constant value. Several embedded compilers support this, as does Microsoft Visual C. Code checking tools such as PC-LINT will flag code that attempts to assign constants to an enum.

Article last edited on: 2011-03-08 13:42:42

Rate this article

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