Enumeration question

This is a discussion on Enumeration question within the C++ Programming forums, part of the General Programming Boards category; Hi guys. I try to explain this as best I can. Here is the situation: I have a microprocessor app ...

Enumeration question

Hi guys. I try to explain this as best I can. Here is the situation: I have a microprocessor app and programming software for the micro, with identical memory mapping.

In my programming software, there is form with indices 0, 1, 2, casted to an enum

Code:

enum
{
0, X
1, Y
2, Z
}

And then the parameter gets written to the processor memory.

However, by accident, in the embedded code the enum was accidently defined as

Code:

enum
{
0, Z
1, Y
2, X
}

Here is whats happening: If I program X or Z to the embedded app and read it in my embedded app, both are seen as '0'. Y is seen as '1' as expected. Why is the underlying reason for this? C++ seems to be handling enums differently than i thought.

I note that your example code is actually syntactically invalid. Anyway, maybe someone with embedded programming knowledge can explain everything given just this information, but to me, you'll need to elaborate on:

Originally Posted by Link_26

If I program X or Z to the embedded app and read it in my embedded app, both are seen as '0'.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.