Indexing an array with litterals

Discussion in 'C Programming' started by Emmanuel Delahaye, Nov 13, 2005.

  1. 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
     
    Emmanuel Delahaye, Nov 13, 2005
    #1
    1. Advertising

  2. 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
     
    Antoine Junod, Nov 13, 2005
    #2
    1. Advertising

  3. Antoine Junod <> 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) <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.
     
    Keith Thompson, Nov 13, 2005
    #3
  4. > > 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
     
    Antoine Junod, Nov 13, 2005
    #4
  5. > > 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
     
    Antoine Junod, Nov 13, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. C
    Replies:
    0
    Views:
    518
  2. Emin
    Replies:
    4
    Views:
    425
    Paul McGuire
    Jan 12, 2007
  3. candide

    Splitting numeric litterals

    candide, Jul 15, 2010, in forum: Python
    Replies:
    12
    Views:
    353
    Steven D'Aprano
    Jul 17, 2010
  4. Skybuck Flying
    Replies:
    30
    Views:
    1,132
    Bill Reid
    Sep 19, 2011
  5. C
    Replies:
    3
    Views:
    238
    Manohar Kamath [MVP]
    Oct 17, 2003
Loading...

Share This Page