Re: Passing a 2 dimensional array from fortran to c++
Rich Townsend wrote:
glen herrmannsfeldt wrote:
(snip)
First (float**) is not a two dimensional array. It is a pointer to
pointer to float. It is often used in place of 2D arrays, but it still
isn't one. Some will even say that a C array declared like:
float x[10][10];
isn't a 2D array, either, but I will disagree.
How so? Surey, x[10] has type (float *)? I thought that in C,
x[i]
is purely syntactic sugar for *(x+i). Am I wrong?
It is *(x+i) but the compiler knows what it is applied to.
float x[10][10];
will allocate 100 contiguous float values, just like a Fortran array.
When you say x[i][j] it computes 10*i+j, scaled by sizeof(float) to
find the address of the array element. It will also do that for
*(*(x+i)+j) for an array with that declaration.
I believe the wording is that x[10] decays to (float*),
but x is not, and does not decay to, (float**). You can't,
for example, pass x to a subroutine with a float** dummy argument.
As a function dummy argument declaration,
float *y; and float y[]; are equivalent.
float **x; and float x[][10]; are not.
-- glen
.
Relevant Pages
- Re: Help a beginner - function with pointer ...
... i thought (float *) T would be appealing to ... The result is the value obtained by converting the ... `T' refers to a one-dimensional array whose elements are also ... using a pointer to the array's first element. ... (comp.lang.c) - Re: weird code.
... never seen this kind of declaration ever. ... The variable data is a float pointer? ... array of 16384 float objects. ... (comp.lang.c) - Re: new foo[42]
... > First question: ... 42 type 'float' objects, and returns the address ... value in the pointer object 'foo'. ... The first form above dynamically allocates an array (which ... (comp.lang.cpp) - Re: weird code.
... The variable data is a float pointer? ... array of 16384 float objects. ... We just write `sizeof *data' and the compiler (knowing what ... (comp.lang.c) - Re: char **argv & char *argv[]
... "pointer to pointer to char". ... >> pointer)) pointing to the first element of an array. ... so we have to start adding more context. ... type "pointer to char", rather than "array MISSING_SIZE of char". ... (comp.lang.c) |
|