Pointers to 2D arrays
Author Message
Pointers to 2D arrays

Okay, I have a 2D array of floats, e.g.

static const float coordinates[][ 3 ] =
{
{ 1.0, 2.0, 3.0 }, { 4.0, 5.0, 6.0 },
};

What I want to do is hold a pointer to this variable (for example,
something like float* pF = coordinates) but I cannot for the life of me
think how to do this.   Probably extremely trivial solution and I'll kick
myself, but could someone please shed light on the problem.
Thanks.

O.

Tue, 15 Feb 2000 03:00:00 GMT
Pointers to 2D arrays

Quote:

>Okay, I have a 2D array of floats, e.g.

>  static const float coordinates[][ 3 ] =
>  {
>     { 1.0, 2.0, 3.0 }, { 4.0, 5.0, 6.0 },
>  };

>What I want to do is hold a pointer to this variable (for example,
>something like float* pF = coordinates) but I cannot for the life of me
>think how to do this.   Probably extremely trivial solution and I'll kick
>myself, but could someone please shed light on the problem.
>Thanks.

When in doubt, use typedef:

typedef float coord_t[3];

coord_t coordinates[] = { { 1.0, 2.0, 3.0 }, /*..etc...*/ }

coord_t *pF = coordinates;

When not in doubt, whip out the declaration syntax expertise:

float (*pF)[3] = coordinates;

Tue, 15 Feb 2000 03:00:00 GMT
Pointers to 2D arrays

You might try pF = &(coordinates[0][0]);  or   pF = (int *)&(coordinates);

Quote:
> Okay, I have a 2D array of floats, e.g.

>   static const float coordinates[][ 3 ] =
>   {
>      { 1.0, 2.0, 3.0 }, { 4.0, 5.0, 6.0 },
>   };

> What I want to do is hold a pointer to this variable (for example,
> something like float* pF = coordinates) but I cannot for the life of me
> think how to do this.   Probably extremely trivial solution and I'll kick
> myself, but could someone please shed light on the problem.
> Thanks.

> O.

Tue, 22 Feb 2000 03:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages