Jump to content

Recommended Posts

Hey,

 

I have a simple problem with enums:

 

enum PHASE {A,B,C,D};

 

This line reports these compiler errors:

 

error: missing right brace

error: missing semicolon

error: failure

 

If I change the line to this:

 

enum PHASE {AF,BA,CE,DB};

 

This will not produce an error.

 

Here's another strange thing:

 

If I use this line:

 

enum Byp_Pos {BYP_OFF,BYP_OPEN,BYP_CLOSE};

 

It compiles as expected.

 

If I change the line to this:

 

enum Bypass_Position {BYP_OFF,BYP_OPEN,BYP_CLOSE};

 

Then I get an error on the first bracket in main:

error: general error

error: failure

 

What's with enums? I'd like to use enums, but it seems that they only work under rare conditions?

 

Dan

Share this post


Link to post
Share on other sites

Remember that some single character names, such as C and D, are already defined as register bit names (see pic header file).

 

enum Bypass_Position {BYP_OFF,BYP_OPEN,BYP_CLOSE};

 

This enum works for me !

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites
Remember that some single character names, such as C and D, are already defined as register bit names (see pic header file).

 

enum Bypass_Position {BYP_OFF,BYP_OPEN,BYP_CLOSE};

 

This enum works for me !

 

Cheers

 

Reynard

 

Reynard,

 

Oh, BTW, I am running version 6.89 with an 18F4550 pic.

 

"C and D, are already defined " Yea, that's what I figured, so I tried changing to something more unique. But it doesn't make sense for the compiler to report that there's a missing bracket, and a missing semicolon. Looks like a bug.

 

I'm still wondering why I get the error on the first bracket in main if I change the enum name.

 

Dan

Edited by danmc77

Share this post


Link to post
Share on other sites

It looks like the compiler errors on the C and forgets about the rest of the line giving the odd-ball error codes.

 

;/////////////////////////////////////////////////////////////////////////////////
;// Code Generator: BoostC Compiler - http://www.sourceboost.com
;// Version	   : 6.89
;// License Type  : Full License
;// Limitations   : PIC18 max code size:Unlimited, max RAM banks:Unlimited, Non commercial use only
;/////////////////////////////////////////////////////////////////////////////////

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

unsigned char fred1;
unsigned int fred2;

void main()

{
fred1 = BYP_OPEN;
0004  0E01		  MOVLW 0x01
0006  6E03		  MOVWF gbl_fred1

fred2 = BYP_CLOSE;
0008  0E02		  MOVLW 0x02
000A  6E01		  MOVWF gbl_fred2
000C  6A02		  CLRF gbl_fred2+D'1'

}
000E  0012		  RETURN


////////////////////////////////////////
// Code with no source :-)
////////////////////////////////////////
0000  EF08F000	  GOTO	_startup

0010			_startup
0010  EF02F000	  GOTO	main

 

I am using V6.89 and PIC18F4550 with no problem on your enum.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites
"C and D, are already defined " Yea, that's what I figured, so I tried changing to something more unique. But it doesn't make sense for the compiler to report that there's a missing bracket, and a missing semicolon. Looks like a bug.

 

It's not a bug. Your code looks like this:

 

enum PHASE {A,B,C,D};

 

But C & D are already defined. So, after the preprocessor is run, the code the compiler gets looks like this:

 

enum PHASE {A,B,0x00000000,0x00000005};

 

These values are taken from the PIC18F4550 target header file. Since you are trying to enumerate a number instead of a variable, the compiler thinks that you forgot to close your brace and end the command. This code results in the same error:

 

enum PHASE {A,B

unsigned char a = 0;

 

So, the compiler just thinks you made a typo.

 

- Bill

Share this post


Link to post
Share on other sites
"C and D, are already defined " Yea, that's what I figured, so I tried changing to something more unique. But it doesn't make sense for the compiler to report that there's a missing bracket, and a missing semicolon. Looks like a bug.

 

It's not a bug. Your code looks like this:

 

enum PHASE {A,B,C,D};

 

But C & D are already defined. So, after the preprocessor is run, the code the compiler gets looks like this:

 

enum PHASE {A,B,0x00000000,0x00000005};

 

These values are taken from the PIC18F4550 target header file. Since you are trying to enumerate a number instead of a variable, the compiler thinks that you forgot to close your brace and end the command. This code results in the same error:

 

[code]enum PHASE {A,B

unsigned char a = 0;

 

So, the compiler just thinks you made a typo.

 

- Bill

 

OK, so then should the preprocessor complain that C and D are already defined?

Share this post


Link to post
Share on other sites

Well explained reason Bill.

 

A simple 'Invalid Symbol' or something would have explained the error better though.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites
...A simple 'Invalid Symbol' or something would have explained the error better though...

 

Compiler has been changed to report "error: unexpected constant" for this kind of errors. This change will be available in the next release.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
...A simple 'Invalid Symbol' or something would have explained the error better though...

 

Compiler has been changed to report "error: unexpected constant" for this kind of errors. This change will be available in the next release.

 

Regards,

Pavel

 

Excellent.

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