2

I am working on some C code.

There is a function like this;

void Get(double x_la[], 
double y_la[], 
double z_la[])

in the function body, for some other reasons I create;

double (*la)[3];

As far as I understood, x_la, y_la and z_la are pointers of the type double.

I need to "connect" the pointers involved in "la" wiht the previous ones, so I thought trying;

la[0]=x_la;
la[1]=y_la;
la[2]=z_la;

but during compilation with gnu compiler I get the error;

error: incompatible types in assignment of 'double*' to 'double [3]'

What I am doing wrong? Otherwise, how could do it well?

Thanks

P.D. Is it exactly the same to declare

double y_la[]

or

double *y_la

?

Daniel Daranas
  • 22,454
  • 9
  • 63
  • 116
Open the way
  • 26,225
  • 51
  • 142
  • 196
  • Array declarations are extensively covered in [this answer](http://stackoverflow.com/questions/2250397/interpretation-of-int-a3/2250448#2250448). – Georg Fritzsche Jun 03 '10 at 16:28
  • This may help: http://stackoverflow.com/questions/859634/c-pointer-to-array-array-of-pointers-disambiguation, especially the answer about `cdecl`. – Seth Jun 03 '10 at 16:30
  • thanksa lot to everybody, I understand it better now !! – Open the way Jun 03 '10 at 18:22

1 Answers1

4

You want double *la[3];.

As you have it, la isn't a pointer to double but a single pointer to an array of three things, and so each la[i] is still a pointer to something other than a double, and doubly problematic because you really only have one of them.

As to the second question, those are only the same in a parameter list, and even then only in an old-style declaration. Once you type in a prototype, then type conformance is governed by a more precise set of rules.

DigitalRoss
  • 143,651
  • 25
  • 248
  • 329