Solved

valid enum?

Posted on 2016-08-10
6
68 Views
Last Modified: 2016-08-10
enum
{
      REVERSE,
      FORWARD,

      NUM_ZONES
};

My embedded target board is based on Renesas RH850F1L Microcontroller.  My language is Embedded 'C'.

I get compile error "expected an identifier" when I create above enum.  Is it a valid enum?  
I want to use members of this enum to create an array and also use members of this enum for array index.

I can do #define instead but can this enum work in place of #define?
0
Comment
Question by:naseeam
  • 3
  • 2
6 Comments
 
LVL 45

Accepted Solution

by:
Kdo earned 400 total points
ID: 41750480
You might try naming the enumeration, though that's not a requirement.

enum direction_t
{
      REVERSE,
      FORWARD,
      NUM_ZONES
};

Are you duplicating a declaration?

enum direction_t
{
      DIR_REVERSE,
      DIR_FORWARD,
      DIR_NUM_ZONES
};


Kent
1
 

Author Comment

by:naseeam
ID: 41750646
I get the same error.  No, I'm not duplicating the declaration.
0
 
LVL 45

Expert Comment

by:Kdo
ID: 41750770
REVERSE and FORWARD are pretty common words.  There's a reasonable chance that they could already be define in another #include file.

Can you post a few lines before and after the enum declaration?

Thanks!
1
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 32

Assisted Solution

by:sarabande
sarabande earned 100 total points
ID: 41750831
Are you duplicating a declaration?

actually it is a definition  of a constant or a preprocessor macro which must not be duplicated.

in c you may try

typedef enum
{
      DIR_FORWARD,
      DIR_REVERSE,
      NUM_DIRECTIONS
} EDIRECTION;

Open in new window


if the c compiler is not an ansi c compiler, it might be unable to use enum.

Sara
0
 

Author Comment

by:naseeam
ID: 41750868
Kent:

You were actually correct.  Your solution worked.
0
 

Author Closing Comment

by:naseeam
ID: 41750872
Thank you!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now