Gamestudio Links
Zorro Links
Newest Posts
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
Release 2.68 replacement of the .par format
by Martin_HH. 09/23/25 20:48
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 17,605 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 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: 594
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 594
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,806
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

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


Moderated by  Petra 

Gamestudio download | 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