Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Ayumi), 1,170 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
How to pass var pointer? #298306
11/13/09 17:54
11/13/09 17:54
Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Puppeteer Offline OP
Expert
Puppeteer  Offline OP
Expert

Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Code:
function test(var* bla)
{
	bla=2;
}

	var asd=0;
	test(asd);
	error(str_for_num(NULL,asd));



this doesnt work (asd!=2). why?

Last edited by Puppeteer; 11/13/09 17:55.

Formally known as Omega
Avatar randomness by Quadraxas & Blade
http://omegapuppeteer.mybrute.com
Re: How to pass var pointer? [Re: Puppeteer] #298308
11/13/09 18:21
11/13/09 18:21
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Code:
function test(var* bla)
{
	*bla=2;
}




3333333333
Re: How to pass var pointer? [Re: Quad] #298319
11/13/09 19:57
11/13/09 19:57
Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Puppeteer Offline OP
Expert
Puppeteer  Offline OP
Expert

Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Originally Posted By: offtopic
Thank you again.
Why do you know so much more than me? grin



Formally known as Omega
Avatar randomness by Quadraxas & Blade
http://omegapuppeteer.mybrute.com
Re: How to pass var pointer? [Re: Puppeteer] #298324
11/13/09 21:16
11/13/09 21:16
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
coincidence. you just happen to ask about things i know grin


3333333333
Re: How to pass var pointer? [Re: Quad] #298443
11/15/09 03:20
11/15/09 03:20
Joined: Nov 2009
Posts: 34
S
Sepiantum Offline
Newbie
Sepiantum  Offline
Newbie
S

Joined: Nov 2009
Posts: 34
function test(var* num){
*num = 2;
}

var asd=0;
test(&asd);

Just to let you know, a pointer is an address. In this case, an address of a var. So it points to the var. When you say *num, it means whatever is pointed by num, in this case, asd and sets it to 2. And over here: test(&asd), you have to pass the address of asd to the function, or else it just creates a local copy and cannot edit it. Go read up on some ANSI C if you want to truly understand pointers. And, please don't use ent.x if you defined something like ENTITY* ent = ent_create(); Use ent->x. It's standard C, you know.

Re: How to pass var pointer? [Re: Sepiantum] #298455
11/15/09 08:02
11/15/09 08:02
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
when you say test(asd); and use asd as a pointer, lite-c understands that and gives you it's pointers, so when you are using lite-c functions you GENARALLY wont need the preceeding &. Altough lite-c is fully compatible with ANSI-C, lite-c is not ANSI.

(so you can both pass a VECTOR or a VECTOR* to a function that takes VECTOR* as parameter)

Last edited by Quadraxas; 11/15/09 08:04.

3333333333
Re: How to pass var pointer? [Re: Quad] #298519
11/15/09 18:06
11/15/09 18:06
Joined: Nov 2009
Posts: 34
S
Sepiantum Offline
Newbie
Sepiantum  Offline
Newbie
S

Joined: Nov 2009
Posts: 34
oh well. Still, I like my old code format. It's more understandable.

Re: How to pass var pointer? [Re: Sepiantum] #298568
11/16/09 03:07
11/16/09 03:07
Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Puppeteer Offline OP
Expert
Puppeteer  Offline OP
Expert

Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Code:
void make_identity_matrix(var* mat)
{
   int i,j; 
   for( i= 0 ; i< 4 ; i++ )
	for( j= 0 ; j< 4 ; j++ )
	{
		if(i==j)
		{
			*mat[i][j]=1;
		}
		else
		{
			*mat[i][j]=0;
		}
	}
}


compiler says "dimension of array error."
in
"*mat[i][j]=1;"
and
"*mat[i][j]=0;"

Whats wrong here?
Maybe because he is only passing a pointer to a single var in an array? (but (var** mat) doenst work too)

Last edited by Puppeteer; 11/16/09 03:09.

Formally known as Omega
Avatar randomness by Quadraxas & Blade
http://omegapuppeteer.mybrute.com
Re: How to pass var pointer? [Re: Puppeteer] #298569
11/16/09 03:47
11/16/09 03:47
Joined: Nov 2009
Posts: 34
S
Sepiantum Offline
Newbie
Sepiantum  Offline
Newbie
S

Joined: Nov 2009
Posts: 34
it should be make_identity_matrix(var mat[][4]); Arrays are basically pointers. And you do mat[i][j] instead of *mat[i][j].

Re: How to pass var pointer? [Re: Sepiantum] #298572
11/16/09 03:50
11/16/09 03:50
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
BTW, the lite-c function 'mat_identity' makes a matrix into the identity matrix.

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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