Gamestudio Links
Zorro Links
Newest Posts
MinMax function on History t6 file
by LucasJoshua. 11/21/26 14:28
What are you working on?
by rayp. 11/20/26 18:10
FXCM => AVA Trade Plugin???
by Martin_HH. 11/17/26 17:02
contractUpdate() is filtering if >2 rows
by mistery. 11/09/26 12:06
New Zorro version 3.15
by jcl. 11/09/26 09:24
Removing outliers from files
by jcl. 11/04/26 10:30
[MED] Import from FBX (2010) missing!!!
by rayp. 11/03/26 14:33
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
5 registered members (LucasJoshua, Quad, Grant, EvanTJ, 1 invisible), 37,257 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EvanTJ, rht, MaliceTheMaker, Haitao_Ren, JimSimons
19250 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