incompatible pointer type?

This is a discussion on incompatible pointer type? within the C Programming forums, part of the General Programming Boards category; Hey, I need to pass a **pointer of an array as a function argument, but for some reason I keep ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    11

    incompatible pointer type?

    Hey,
    I need to pass a **pointer of an array as a function argument, but for some reason I keep getting the error "warning: assignment from an incompatible pointer type". As you can tell I'm pretty new to using C, so I'll post my code and hope someone can point out the blatant error .

    double x[2][2],y[2][2];
    double **u;
    double **v;

    x[0][0]=x[1][0] = 4;
    x[0][1]=x[1][1] = -3;

    y[0][0]=y[1][0] = 1;
    y[0][1]=y[1][1] = -1;

    u = &x; //this is where the compiler error occurs.
    v = &y;

    functioncall(u,v); //these arguments need to be of the type const double**

    Cheers for any help,
    Kieran

  2. #2
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    You should use

    Code:
    u = x;
    Because u and x are both pointers to pointers. x[2][2] is like **x.

    By using * you dereference a variable (you get the value the pointer is pointing to).
    By using & you get the address of a variable (address is the location in memory).

    So using
    Code:
    u = &x;
    you make u point to x as if it is declared as ***x. Pointers can be hard in the beginning.
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    11
    Quote Originally Posted by Ideswa View Post
    You should use

    Code:
    u = x;
    Because u and x are both pointers to pointers. x[2][2] is like **x.

    By using * you dereference a variable (you get the value the pointer is pointing to).
    By using & you get the address of a variable (address is the location in memory).

    So using
    Code:
    u = &x;
    you make u point to x as if it is declared as ***x. Pointers can be hard in the beginning.
    I've already tried that, still get the same error :S.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The name of an array is not actually a pointer. It's close for most purposes, but it's not the same thing. It's actually a pointer to an array of type T. So you're incorrect when you try to pass it as a pointer to a pointer. You probably want something like this.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. warning: assignment from a incompatible pointer type
    By enderandrew in forum C Programming
    Replies: 8
    Last Post: 09-22-2007, 05:07 AM
  2. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 04:36 AM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21