Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (rki, AndrewAMD), 407 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 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