Sujet : Re: New VSI post on Youtube
De : arne (at) *nospam* vajhoej.dk (Arne Vajhøj)
Groupes : comp.os.vmsDate : 21. Aug 2024, 19:13:24
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <va5ao4$3v0jf$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : Mozilla Thunderbird
On 8/21/2024 8:26 AM, chrisq wrote:
On 8/21/24 02:25, Lawrence D'Oliveiro wrote:
On Tue, 20 Aug 2024 09:47:36 -0400, Arne Vajhøj wrote:
Few languages support multiple return values.
>
Even in C and Fortran, a function can return a struct.
Better to declare the struct externally, then pass a pointer
to it. Much tidier.
In C one should definitely return a pointer to struct and not
a struct.
It looks like VSI Fortran cannot return a structure as function
result, but VSI Pascal can return a record as function result.
And it is returned as a pointer argument under the hood.
$ type s.pas
module s;
type
iiituple = record
a : integer;
b : integer;
c : integer;
end;
[global]
function get : iiituple;
var
res : iiituple;
begin
res.a := 123;
res.b := 456;
res.c := 789;
get := res;
end;
end.
$ pas s
$ type m.c
#include <stdio.h>
struct iiituple
{
int a;
int b;
int c;
};
void get(struct iiituple *res);
int main()
{
struct iiituple res;
get(&res);
printf("%d %d %d\n", res.a, res.b, res.c);
return 0;
}
$ cc m
$ link m + s
$ run m
123 456 789
Arne