Gamestudio Links
Zorro Links
Newest Posts
Indicator coding
by danatrader. 05/30/20 21:41
Out of Sample
by AndrewAMD. 05/30/20 21:12
Trading Community Project
by danatrader. 05/30/20 20:28
MT4/5 - wrong M1 time
by Grat. 05/30/20 19:14
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 05/30/20 15:18
Windows 10 file_write error
by AndrewAMD. 05/30/20 13:57
stencil blur does not work - SOLVED
by NicolaB. 05/30/20 12:13
Question about Pattern - Workshop7
by danatrader. 05/30/20 09:09
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
11 registered members (3run, alibaba, danatrader, Grat, ozgur, AndrewAMD, kvm, Dooley, 2 invisible), 525 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
PBSeven, Hardi01, Giuseppe, AdamWu, gariki
18460 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
C-lite does not allow a function to return a struct? #479554
04/06/20 03:26
04/06/20 03:26
Joined: Oct 2018
Posts: 67
J
JamesHH Offline OP
Junior Member
JamesHH  Offline OP
Junior Member
J

Joined: Oct 2018
Posts: 67
This toy example, which I believe is standard C code, is failing to compile in Zorro:


struct HIT {
int lower_barrier_hit, upper_barrier_hit;
char first_hit;
};

struct HIT compute_paths(vars x) {
struct HIT hit;

hit.lower_barrier_hit = 1;
hit.upper_barrier_hit = 2;
hit.first_hit = 'u';

return hit;
}

function run() {
vars price = series(priceClose());

struct HIT hit = compute_paths(price);
}


This gives:

Syntax error: Wrong type SETRETV:::STRUCT@16
< return hit; >

Re: C-lite does not allow a function to return a struct? [Re: JamesHH] #479560
04/06/20 08:59
04/06/20 08:59
Joined: Apr 2008
Posts: 299
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 299
Austria
In classic C you cannot return a struct. New C/C++ versions can but believe me you normally dont want to do it. Return a struct pointer instead.

HIT* compute_paths(vars x) {
static HIT hit;
...
return &hit;
}

Re: C-lite does not allow a function to return a struct? [Re: JamesHH] #479592
04/09/20 07:19
04/09/20 07:19
Joined: Dec 2014
Posts: 171
Germany
Smon Offline
Member
Smon  Offline
Member

Joined: Dec 2014
Posts: 171
Germany
I have worked around that issue by updating a global struct instead of returning one.

Re: C-lite does not allow a function to return a struct? [Re: JamesHH] #479594
04/09/20 10:31
04/09/20 10:31
Joined: Feb 2017
Posts: 979
Chicago
AndrewAMD Online
User
AndrewAMD  Online
User

Joined: Feb 2017
Posts: 979
Chicago
You can also supply a pointer to a struct as an argument and fill it with values.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1