By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,497 Members | 2,534 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,497 IT Pros & Developers. It's quick & easy.

Indexing an array with litterals

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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+

Emmanuel Delahaye
Nov 15 '05 #2

P: n/a
> > 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
};


That's really better. Thanks!

-AJ
Nov 15 '05 #3

P: n/a
Antoine Junod <to**@tots-ns.net> writes:
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #4

P: n/a
> > 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.


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
Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.