Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
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
2 registered members (TipmyPip, 1 invisible), 18,789 guests, and 8 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
Runtime array sizing (newbie question) #446342
10/11/14 11:46
10/11/14 11:46
Joined: Oct 2014
Posts: 43
DEVON
S
scotpip Offline OP
Newbie
scotpip  Offline OP
Newbie
S

Joined: Oct 2014
Posts: 43
DEVON
Hi

Really enjoying digging into Zorro - elegant, powerful, stable, fast and well documented... What's not to like? Many thanks to the developers!

But I'm not understanding why I'm getting a compiler syntax error when I try to initialise an array length with an integer constant set at runtime.

Obviously, scaling the array with a primitive int compiles:

Code:
int foo[12];



My understanding is that in C any integer constant should also work, but these are failing to compile in Lite-C:

Code:
#define FOO_LENGTH 12;
int foo[FOO_LENGTH];



Code:
const int FOO_LENGTH = 12;
int foo[FOO_LENGTH];



(I have to set the values in a loop, so I can't size the array with the int foo = {1,2,3} syntax.)

I'd really appreciate some insight into why this is not legal, and suggestions about an alternative approach.

Thanks in advance!

Re: Runtime array sizing (newbie question) [Re: scotpip] #446343
10/11/14 11:50
10/11/14 11:50
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
I don't know anything about Zorro but

#define FOO_LENGTH 12;

defines FOO_LENGTH as "12;" - not as "12". Thus the compiler cannot compile the following code:

int foo[12;];

The solution obviously is to remove the ";" at the end of your define statement.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Runtime array sizing (newbie question) [Re: Superku] #446345
10/11/14 12:20
10/11/14 12:20
Joined: Oct 2014
Posts: 43
DEVON
S
scotpip Offline OP
Newbie
scotpip  Offline OP
Newbie
S

Joined: Oct 2014
Posts: 43
DEVON
@Superku

Many thanks for the super-rapid and super-helpful response!

You are, of course, correct. I've been putting ; at the end of statements in other languages for so long that it's become a reflex. In the first hours of my adventure with C I hadn't spotted that it's not used for #define statements...


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1