Thread: indirection error

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    411

    indirection error

    Lets say I make a function that takes a float*, the idea being that the function can access the values stored in the array.

    bool Checkf(float *colors);

    now inside the function i do this.

    float tred = colors[0];
    float tgrn = colors[1];
    float tblu = colors[2];

    is that right for what I want? I thought it would have to be

    float tred = *colors[0];

    but it gives me an indirection error when i do that.

    The problem im haveing is with this function, I dont think its getting the right values from the passed array, but it still might be something else I havent thought of yet.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >float tred = colors[0];
    This is correct. It's essentially saying take the value of the address pointed to by colors + 0 and place it in the float variable tred. You pass the float pointer by saying float *colors, which is the same as float colors[]. Array notation is allowed, and thank god for that

    >float tred = *colors[0];
    This is not correct. It says to go to the address pointed to by the value of the address of colors + 0 and place the value of that location in the float variable tred. colors[0] is not a pointer, it's a float variable so the indirection is invalid, you can't dereference a float variable.

    The two are very different, but subtlely so. I can see how this would be confusing.

    -Prelude
    Last edited by Prelude; 02-11-2002 at 12:09 AM.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM