Indexing an array with litterals

E

Emmanuel Delahaye

Antoine Junod a écrit :
I would like to index an "array" (semantic, not logic) with litterals in
a smart way. I could do as follow:

#define WHILE 0
#define IF 1
#define FOR 2
...

or better

enum my_index
{
I_WHILE,
I_IF,
I_FOR,
I_NB
};
and then use WHILE IF FOR to index my array. But that is not really
smart.

What could be smarter ?
 
A

Antoine Junod

Hello,

I would like to index an "array" (semantic, not logic) with litterals in
a smart way. I could do as follow:

#define WHILE 0
#define IF 1
#define FOR 2
....

and then use WHILE IF FOR to index my array. But that is not really
smart.

Any idea? Thanks a lot for your help
-AJ
 
K

Keith Thompson

Antoine Junod said:
I would like to index an "array" (semantic, not logic) with litterals in
a smart way. I could do as follow:

#define WHILE 0
#define IF 1
#define FOR 2
...

and then use WHILE IF FOR to index my array. But that is not really
smart.

I have no idea what you mean by "semantic, not logic". Since you put
the word the word "array" in quotation marks, I'm guessing you don't
mean an array in the usual C sense, but I don't know what you do mean.

I suspect you're looking for an enumeration type.
 
A

Antoine Junod

I would like to index an "array" (semantic, not logic) with litterals in
or better

enum my_index
{
I_WHILE,
I_IF,
I_FOR,
I_NB
};

That's really better. Thanks!

-AJ
 
A

Antoine Junod

I would like to index an "array" (semantic, not logic) with litterals in
I have no idea what you mean by "semantic, not logic". Since you put
the word the word "array" in quotation marks, I'm guessing you don't
mean an array in the usual C sense, but I don't know what you do mean.

Thanks for your answer Keith. Semantic means it was not a obligation for
me to use an array but I needes a structure that works a bit like an
array.
But the question was not well asked. I should preprare my questions a
bit better.

-AJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top