Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

calling a method with a double dimensioned array

25 views
Skip to first unread message

Lynn McGuire

unread,
Jan 25, 2023, 10:53:03 PM1/25/23
to
Hi,

I am calling

int gettmp (integer *i, integer a, longint *s, longint *temp [100],
integer *fin);

with

integer a, b, i, j;
longint s[2];
integer ii, ij, fin;
longint temp [2] [100];

gettmp (&i, a, s, temp, &fin);

But I am getting "Error C2664 'int gettmp(integer *,integer,longint
*,longint *[],integer *)': cannot convert argument 4 from 'longint
[2][100]' to 'longint *[]' chemtran_dll c:\dii\shr\struct\tree.cpp 116 "
from
Visual C++ 2015.

And advice here ?

Both "longint" and "integer" are defined to be "long long" types.

Thanks,
Lynn McGuire

Ben Bacarisse

unread,
Jan 25, 2023, 11:04:24 PM1/25/23
to
Lynn McGuire <lynnmc...@gmail.com> writes:

> Hi,
>
> I am calling
>
> int gettmp (integer *i, integer a, longint *s, longint *temp
> [100], integer *fin);

The temp argument has type longint **. The 100 is ignored and the []s
just mean a pointer in this context.

> with
>
> integer a, b, i, j;
> longint s[2];
> integer ii, ij, fin;
> longint temp [2] [100];
>
> gettmp (&i, a, s, temp, &fin);

The type of temp here is longint (*)[100]. It's a pointer to the first
of some (in this case two) arrays of 100 longints.

> But I am getting "Error C2664 'int gettmp(integer *,integer,longint *,longint *[],integer *)': cannot convert argument 4 from 'longint
> [2][100]' to 'longint *[]' chemtran_dll c:\dii\shr\struct\tree.cpp 116 " from
> Visual C++ 2015.
>
> And advice here ?

The type you need for the parameter is longint (*temp)[100]. You could
write it as longint temp[2][100] if you wanted to, but I wouldn't.

--
Ben.

Lynn McGuire

unread,
Jan 26, 2023, 3:13:20 PM1/26/23
to
Thanks ! I changed gettmp to:

int gettmp (integer *i, integer a, longint *s, longint temp [][100],
integer *fin);

and now it compiles.

Sincerely,
Lynn McGuire


Lynn McGuire

unread,
Jan 29, 2023, 2:48:30 PM1/29/23
to
I would like to put

int gettmp (integer *i, integer a, longint *s, longint temp [2][100],
integer *fin);

But apparently that is illegal in C++.

Thanks,
Lynn


Ben Bacarisse

unread,
Jan 29, 2023, 3:30:19 PM1/29/23
to
Lynn McGuire <lynnmc...@gmail.com> writes:

> On 1/26/2023 2:12 PM, Lynn McGuire wrote:
>> On 1/25/2023 10:04 PM, Ben Bacarisse wrote:
>>> Lynn McGuire <lynnmc...@gmail.com> writes:
<edited quotes>
>>>> I am calling
>>>>
>>>>      int gettmp (integer *i, integer a, longint *s, longint *temp
>>>>      [100], integer *fin);
>>>
>>> The temp argument has type longint **.  The 100 is ignored and the []s
>>> just mean a pointer in this context.

>>>> with

>>>>      longint temp [2] [100];
>>>>
>>>>      gettmp (&i, a, s, temp, &fin);
>>>
>>> The type of temp here is longint (*)[100].  It's a pointer to the first
>>> of some (in this case two) arrays of 100 longints.

>>>> And advice here ?
>>>
>>> The type you need for the parameter is longint (*temp)[100].  You could
>>> write it as longint temp[2][100] if you wanted to, but I wouldn't.
>>
>> Thanks !  I changed gettmp to:
>> int gettmp (integer *i, integer a, longint *s, longint temp [][100],
>> integer *fin);
>> and now it compiles.

> I would like to put
>
> int gettmp (integer *i, integer a, longint *s, longint temp [2][100], integer *fin);
>
> But apparently that is illegal in C++.

I don't think so, but it might not mean what you think it means. The
"first" dimension is simply ignored. longint temp[2][100] is (in a
parameter position) the same as your previous solution.

Can you post code that shows what the problem is?

But I am curious as to why you want to write that 2 in there. Do you
want to write just to help the reader? If so, no problem, but if you
want to pass the 2 so the function can, for example, know the size of
the array, they you are going to have to use a different type -- the
simplest being to pass a reference to the whole array:

int gettmp(..., longint (&temp)[2][100], ...);

I think it's worth pointing out (since I think this is from your Fortran
to C++ tool) that if the array dimensions might not always be
compile-time constants you will have to start using more sophisticated
C++ types. And if that is going to happen eventually, you would be
better off starting now.

--
Ben.
0 new messages