Solved

valid enum?

Posted on 2016-08-10
6
72 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 33

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
undefined reference to `bswap_128' 9 136
Why adding test code changes the build ? 11 130
C++ vs C compilers 13 157
Unable to start eclipse ? 17 127
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

948 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