Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 677 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 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: 72
J
JamesHH Offline OP
Junior Member
JamesHH  Offline OP
Junior Member
J

Joined: Oct 2018
Posts: 72
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: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
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: 206
Germany
Smon Offline
Member
Smon  Offline
Member

Joined: Dec 2014
Posts: 206
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: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
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