Jump to content
Sign in to follow this  
Guest Joe

Switch Statment And Enums

Recommended Posts

Guest Joe

Hi,

 

Compiler fails on the following code (simplified):

 

enum failsafe_states // failsafe states
{
 FAILSAFE_STATE_OFF = 0  
,FAILSAFE_STATE_ON
,FAILSAFE_STATE_HOLD
};



	 BYTE apples = FAILSAFE_STATE_ON;
	 switch( apples )
	 {
   case FAILSAFE_STATE_ON:
  	 break;
   
   default:
   case FAILSAFE_STATE_OFF:
  	 break;
   
   case FAILSAFE_STATE_HOLD:
  	 break;
	 }

 

 

Compiling...

 

"C:\Program Files\SourceBoost\boostc.pic16.exe" -t PIC12F675  ServoSwitch.c

 

BoostC Optimizing C Compiler Version 2.0.1 Beta (for PIC16 architecture)

http://www.picant.com/c2c/c.html

Copyright© 2004-2005 Pavel Baranov

Copyright© 2004-2005 David Hobday

 

 

Don't know how to handle node with ID: 0 (FAILSAFE_STATE_ON)

ServoSwitch.c(183:7): error: error in 'case' label

failure

Failed to locate output file 'ServoSwitch.obj'

Done

 

Failed

the if/else equlivent works fine, but generates huge code :blink: not sure why!

 

if( apples == FAILSAFE_STATE_ON )
{
}
else
if( apples == FAILSAFE_STATE_OFF )
{
}
else
if( apples == FAILSAFE_STATE_HOLD )
{
}
else
{
    // default
}

 

change the enum to #define ... and the switch works...

 

#define FAILSAFE_STATE_OFF 	 0  
#define	FAILSAFE_STATE_ON  1
#define FAILSAFE_STATE_HOLD  2

 

 

Joe

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...