Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
1 registered members (Grant), 999 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 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: 42
DEVON
S
scotpip Offline OP
Newbie
scotpip  Offline OP
Newbie
S

Joined: Oct 2014
Posts: 42
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: 42
DEVON
S
scotpip Offline OP
Newbie
scotpip  Offline OP
Newbie
S

Joined: Oct 2014
Posts: 42
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