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
0 registered members (), 16,302 guests, and 5 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
"size_of" macro has gone buggy again, very possibly... #386235
10/31/11 10:47
10/31/11 10:47
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Hiya JCL.

It looks as if the 'sizeof' hes developed a bug again.
It can no longer safely be used in expressions.
(tested with same results in 8.30.2 and 8.30.3 commercials, maybe more)

Code:
// this works fine.  V2 is made a pointer to a short.
var n = sizeof(short);
short *v1=(short*)sys_malloc(n*5), *v2;
//

// this FAILS.  V2 is made a pointer to a short pointer ... or something
short *v1=(short*)sys_malloc(sizeof(short)*5), *v2;



Here is my discussion in the Lite-C thread.

Please pay attention to the most recent posts, and one from Bunsen followed
by one from Rei_Ayanami that sum the problem up perfectly.

And here is a stand-alone script to demonstrate the problem.
Click to reveal..
Code:
#include <acknex.h>
#include <default.c>
//
//
//---------------------------------------------------------------------------------------
//
//
void main()
{
	wait(1);			level_load(NULL);		wait(1);				diag("\n\n\n");
	draw_textmode("Courier",0,25,100);	warn_level = 3;	on_esc = NULL;
	VECTOR col;		vec_fill(col, 255);	var idx;
	//------------------------------------------------------------------------------------
	//
	//
	short *row_1 = (short*)sys_malloc(sizeof(short)*20);
	short *row_2 = (short*)sys_malloc(sizeof(short)*20);
	//
	//////////////////////////////////////////////////////////////////////////////////////
	// THIS IS THE AREA TO WATCH ////  only un-comment one line at a time  ///////////////
	//
	short *point1, *point2, *dummy=sys_malloc(sizeof(short));		//both work
//	short *point1, *dummy=sys_malloc(sizeof(short)), *point2;		//only row_2 fails
//	short *dummy=sys_malloc(sizeof(short)), *point1, *point2;		//both fail
	// now watch this NEW discovery!!
//	short *dummy=sys_malloc(250), *point1, *point2;		//both WORK if size_of function not used
	//
	//////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////
	//
	point1 = &row_1[5];		point2 = &row_2[5];
	//
	while(!key_esc)
	{
		memset(row_1, 0, sizeof(short)*20);		memset(row_2, 0, sizeof(short)*20);
		//
	//------------------------------------------------------------------------------------
		if(key_1)	{	for(idx=0;  idx<9;  idx++)		row_1[idx+5] = idx+1;		}
		if(key_2)	{	for(idx=0;  idx<9;  idx++)		row_2[idx+5] = idx+1;		}
		//
		if(key_5)	{	for(idx=0;  idx<9;  idx++)		point1[idx] = idx+1;		}
		if(key_6)	{	for(idx=0;  idx<9;  idx++)		point2[idx] = idx+1;		}
	//------------------------------------------------------------------------------------
		//
		draw_text("Array  0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.", 100, 100, col);
		draw_text("Row_1", 100, 130, col);		draw_text("Row_2", 100, 160, col);
		for(idx=0;  idx<20;  idx++)	
		{	draw_text(str_for_int(NULL, row_1[idx]), 184+(idx*24), 130, col);
			draw_text(str_for_int(NULL, row_2[idx]), 184+(idx*24), 160, col);		}
		//
		draw_text("Hold the '1' key to fill row_1 directly via 'row_1[x]'", 100, 300, col);
		draw_text("Hold the '2' key to fill row_2 directly via 'row_2[x]'", 100, 340, col);
		draw_text("Hold the '5' key to fill row_1 via pointer 'point1[x]'", 100, 380, col);
		draw_text("Hold the '6' key to fill row_2 via pointer 'point2[x]'", 100, 420, col);
		//
		wait(1);
	}
	//
	//
	//
	//------------------------------------------------------------------------------------
	if(key_shift)	exec("notepad.exe", "acklog.txt");
	sys_exit(0);
}




Thanks dude...




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: "size_of" macro has gone buggy again, very possibly... [Re: EvilSOB] #386242
10/31/11 14:02
10/31/11 14:02
Joined: Jul 2000
Posts: 28,024
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,024
Frankfurt
Yes, indeed the compiler assigns a wrong type to the second pointer, and it's indeed apparently related to sizeof() in the same line. Seems that no one has encountered this strange bug before.

It's too late for 8.30, but this will be fixed in 8.40. Until then, please don't define a pointer in the same line behind a sizeof() call.

Re: "size_of" macro has gone buggy again, very possibly... [Re: jcl] #386253
10/31/11 15:42
10/31/11 15:42
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Thats cool... no rush...

I cant find any records, but Im sure I had trouble with it before it
got fixed last time...

I guess Im the only programmer "dirty" enough to cram so many
declarations onto the same line...

Thanks man


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

Moderated by  jcl, Nems, Spirit, Tobias 

Gamestudio download | 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