1

Is it possible to use a name instead of a number to address an array? I was reading about enum lists and thought it might be possible. ie int array[3] = {something, somethingElse, somethingMore]

array[second] => somethingElse

I am asking as I have an array looking after flags for several functions and would like to be able to use the function name instead of a number to address the array.

bool flag[6] = {1, 1, 1, 1, 1, 0}; // Power, Jump 3, Jump 7, Fade 3, Fade 7, Pause active
1
  • 2
    I'm voting to close this question as off-topic because it's a generic programming question. Commented May 10, 2017 at 21:32

1 Answer 1

3

No, but you can use a struct:

struct flags {
    uint8_t power;
    uint8_t jump3;
    uint8_t jump7;
    .... etc ....
};

struct flags myFlags;

myFlags.power = 1;
if (myFlags.jump3) {
    .... stuff ....
}

Or you can continue to use a simple numeric array and assign names to the numbers, either with #define, const variables, or an enum.

enum flags {
    power, jump3, jump7, fade, fade7, pause
};

bool flag[6] = {1, 1, 1, 1, 1, 0};

flag[power] = 1;
if (flag[jump3]) {
    .... whatever ....
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.