Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 677 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Global array #468503
10/08/17 16:59
10/08/17 16:59
Joined: Dec 2013
Posts: 568
Fuerth, DE
Sphin Offline OP
User
Sphin  Offline OP
User

Joined: Dec 2013
Posts: 568
Fuerth, DE
Code:
var Trend[5];

void main() {
	int i;
	for(i = 0; i < 100; i++) {
 		Trend[i] = i;
		printf("nTrend[%d]: %.0f",i,Trend[i]);
	}
}


Output:
Code:
...
Trend[97]: 97
Trend[98]: 98
Trend[99]: 99


How many elements does this array contain?

Re: Global array [Re: Sphin] #468505
10/08/17 17:47
10/08/17 17:47
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Hi Sphin,

I believe the correct question is: What have you coded to be sure your intended # of elements hasn't been exceeded? laugh

HTH.

Re: Global array [Re: DdlV] #468548
10/09/17 16:51
10/09/17 16:51
Joined: Dec 2013
Posts: 568
Fuerth, DE
Sphin Offline OP
User
Sphin  Offline OP
User

Joined: Dec 2013
Posts: 568
Fuerth, DE
Hi DdlV,

the story behind: I had a problem building the average of a number of values of an array filled through a loop - it was always too high. The cause: there was a Trend[5]-element that I thought was not permitted to exist. I expected the script to crash in such a case. So I extended the try a bit, I also tried a higher number but with #115 the script always crashes. This works only if the array was defined as global, defined as local the script crashes as it should. Okay, seems to be a C secret ... laugh

bye

Re: Global array [Re: Sphin] #468560
10/10/17 06:23
10/10/17 06:23
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
C/C++ does not check array lengths, so you can write past the array size. What then happens depends on what's in the memory past the array. Chance is that's another global array, or some variable that you then overwrite.

Re: Global array [Re: jcl] #468576
10/10/17 17:23
10/10/17 17:23
Joined: Dec 2013
Posts: 568
Fuerth, DE
Sphin Offline OP
User
Sphin  Offline OP
User

Joined: Dec 2013
Posts: 568
Fuerth, DE
Thanks, I didn't know this.


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