Gamestudio Links
Zorro Links
Newest Posts
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Trading Journey
by 7th_zorro. 04/27/24 04:42
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Akow, AndrewAMD, Quad), 733 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Variable Length Arrays #447166
11/21/14 02:36
11/21/14 02:36
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline OP
Senior Member
boatman  Offline OP
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
Hello

I seem to be unable to create an array that uses a variable for its length. This returns a syntax error. For example:

var HighCutoff = 48;
var my_arry[HighCutoff+1];

I also tried declaring the length variable as an int, not a var. Same result.

From my googling, this seems to be a limitation of Lite-C. Is that correct? Does anyone know of a workaround?

Thanks

Re: Variable Length Arrays [Re: boatman] #447167
11/21/14 05:16
11/21/14 05:16
Joined: Dec 2012
Posts: 34
New York
K
kandlekid Offline
Newbie
kandlekid  Offline
Newbie
K

Joined: Dec 2012
Posts: 34
New York
Haven't tried it yet, but maybe using the pre-processor ...

#define HighCutoff 48

var my_arry[HighCutoff+1];

Re: Variable Length Arrays [Re: kandlekid] #447168
11/21/14 08:06
11/21/14 08:06
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Hi boatman, kandlekid. Depends on what you're trying to accomplish. kandlekid's #define parameterizes the code, but the array's size is still defined a compile time. If what you're after is an array dynamically defined at run time, then I believe you need to be using malloc, etc.

HTH.

Re: Variable Length Arrays [Re: DdlV] #447206
11/24/14 22:20
11/24/14 22:20
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline OP
Senior Member
boatman  Offline OP
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
Hi DdlV and kandlekid. Thanks for your suggestions, much appreciated. I can't make it work using the pre-processor; this seems to result in the same syntax error. I'll give malloc a try - don't know anything about this function yet, so I will have a look at the manual and do some googling.

Thanks again


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