Thread: illegal operand

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    16

    Smile illegal operand

    Does anybody see anything wrong with this code?
    I keep getting an "illegal operand" error in my MetroWerks CodeWarrior compiler.

    Your help is appreciated.

    code


    /*wDeck is a two dimensional array with a depth of 13, row and
    column are random integers*/

    *(wDeck+(row*13+column)) = var;


    /code
    don't be a two-bit user

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    137
    Does it work with the code reversed. IE var = .......?
    http://uk.geocities.com/ca_chorltonkids

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    16
    How do you mean that it would depend on how I declared wDeck? I'm not sure I understand.
    don't be a two-bit user

  4. #4
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by monkey_C
    How do you mean that it would depend on how I declared wDeck? I'm not sure I understand.
    int wDeck;
    int *wDeck;
    int **wDeck;
    int wDeck[13];
    int *wDeck[13];
    int wDeck[13*13];
    int wDeck[13][13];

    some of these make sense for your situation, some dont. but the ones that make sense are used in different ways.

    edit: btw these are for a 13x13, not 4x13. oopsie i wasnt thinking when i did it
    Last edited by moi; 09-12-2002 at 05:36 PM.
    hello, internet!

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    16
    OK, wDeck was originally declared in main() as

    int deck [4] [13] = {0};

    and was passed into the function containing my problematic line as

    const int wDeck[][13]

    but I still don't see how that's affecting my code. I think I've just been staring at the same line for too long.
    don't be a two-bit user

  6. #6
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by monkey_C
    OK, wDeck was originally declared in main() as

    int deck [4] [13] = {0};

    and was passed into the function containing my problematic line as

    const int wDeck[][13]

    but I still don't see how that's affecting my code. I think I've just been staring at the same line for too long.
    then access the deck with wDeck[row][column]

    and if it's passed to the function as const, why are yuo modifying it?
    hello, internet!

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    16
    Originally posted by moi
    then access the deck with wDeck[row][column]

    and if it's passed to the function as const, why are yuo modifying it?

    I'm sorry, I made two mistakes, first of all I should have mentioned I was specifically trying to avoid array syntax. Secondly, it is not passed into this function as a const, I was looking at a similar line of code in my next function down.

    Conclusively, it was declared as:

    int wDeck[][13]


    again, sorry.

  8. #8
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    You can't pass const int wDeck[][13] in C.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  9. #9
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by monkey_C
    I'm sorry, I made two mistakes, first of all I should have mentioned I was specifically trying to avoid array syntax. Secondly, it is not passed into this function as a const, I was looking at a similar line of code in my next function down.

    Conclusively, it was declared as:

    int wDeck[][13]


    again, sorry.
    *(*(wdeck + row) + column) is what you need for a multidimentional array.

    edit: note however that all this is is a clumsy and difficult to read version of wdeck[row][column]. there's no reason to be using it really.
    Last edited by moi; 09-12-2002 at 05:56 PM.
    hello, internet!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Illegal Operand
    By Muphin in forum C++ Programming
    Replies: 5
    Last Post: 09-06-2005, 06:49 AM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  3. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 03:53 PM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. illegal operand with & operator
    By Mr_Jack in forum C++ Programming
    Replies: 1
    Last Post: 04-15-2004, 08:26 AM