Gamestudio Links
Zorro Links
Newest Posts
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 (AndrewAMD), 905 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Return a struct pointer #253948
02/27/09 22:32
02/27/09 22:32
Joined: Feb 2006
Posts: 385
Oldenburg,Germany
Ralph Offline OP
Senior Member
Ralph  Offline OP
Senior Member

Joined: Feb 2006
Posts: 385
Oldenburg,Germany
Hi,
Im trying to return a pointer of a struct i've made.
Code:
return (object);//<-- this dont work :/

This is my struct.
Code:
typedef struct DOBJECT{
  var x,y,z;
}DOBJECT;

And this is my function.
Code:
DOBJECT* create_dobject(VECTOR* position){
   DOBJECT* object; //only a temp object
   object.x = position.x;
   //...
   return (object); // return DOBJECT*(object); <- this is not working too
}

DOBJECT* globobj = create_doject(nullvector);


Sorry for my bad english.
Greetings Ralph.

Re: Return a struct pointer [Re: Ralph] #253954
02/27/09 23:21
02/27/09 23:21
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
return(object); is correct, but this line is wrong:
DOBJECT* object;
This just defines a pointer and I think normally is should crash at the line object.x = position.x;

You have to allocate your object:
DOBJECT* object = malloc(sizeof(DOBJECT));

Re: Return a struct pointer [Re: Lukas] #253957
02/27/09 23:41
02/27/09 23:41
Joined: Feb 2006
Posts: 385
Oldenburg,Germany
Ralph Offline OP
Senior Member
Ralph  Offline OP
Senior Member

Joined: Feb 2006
Posts: 385
Oldenburg,Germany
Thank you!
It works perfect!
Now I can put some more functions in my 2d framework! grin

Greetings Ralph.


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