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
2 registered members (Quad, aliswee), 835 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
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