Jump to content
danmc77

Broken Enum?

Recommended Posts

Guys,

 

Take a look at this very simple program:

 

---------------------------------------------------------------------

#include <system.h>

#include <icd2.h>

#include <string.h>

#include <float.h>

 

enum Bypass_PosN {BYP_OFF,BYP_OPEN,BYP_CLOSE};

 

void main()

{

Bypass_PosN=BYP_OFF;

}

---------------------------------------------------------------------

 

When I try to build this, I get this:

 

C:\debug\test.c(9): error: general error

C:\debug\test.c(9): error: failure

 

Now, if I change Bypass_PosN in the enum declaration to something else like, Bypass_Pos, then I get this:

 

C:\debug\test.c(10:2): error: unknown identifier 'Bypass_PosN'

C:\debug\test.c(10:2): error: invalid operand 'Bypass_PosN'

C:\debug\test.c(10:13): error: failed to generate expression

 

Something is not right here. I'm using PIC18 rev 6.89.

 

Please take a look.

 

Thanks,

 

Dan

Share this post


Link to post
Share on other sites

Dan,

 

An enum name is not a variable but a data type. Whether it is a unsigned char or int will depend on the size of the enum values. i.e. if you have BYP_CLOSE=1000, then the compiler will make the variable (fred) a unsigned int. The compiler will use the smallest data type it can.

 

#include <system.h>
enum Bypass_Position {BYP_OFF,BYP_OPEN,BYP_CLOSE};


enum Bypass_Position fred;

void main()
{
fred = BYP_OPEN;
}

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites
Dan,

 

An enum name is not a variable but a data type. Whether it is a unsigned char or int will depend on the size of the enum values. i.e. if you have BYP_CLOSE=1000, then the compiler will make the variable (fred) a unsigned int. The compiler will use the smallest data type it can.

 

#include <system.h>
enum Bypass_Position {BYP_OFF,BYP_OPEN,BYP_CLOSE};


enum Bypass_Position fred;

void main()
{
fred = BYP_OPEN;
}

 

Cheers

 

Reynard

 

 

Pavel, Reynard,

 

Thank you so much for correcting my foolishness.

 

Humbly,

 

Dan

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...

×
×
  • Create New...