Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, Nymphodora, Quad, TipmyPip, Imhotep), 852 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 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: 204
Germany
Smon Offline
Member
Smon  Offline
Member

Joined: Dec 2014
Posts: 204
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,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

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