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
3 registered members (NewbieZorro, TipmyPip, AndrewAMD), 14,749 guests, and 7 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
declaring Vector #270917
06/10/09 14:17
06/10/09 14:17
Joined: Mar 2009
Posts: 276
Cebu City, Philippines
boyax Offline OP
Member
boyax  Offline OP
Member

Joined: Mar 2009
Posts: 276
Cebu City, Philippines
what's the proper way of declaring a vector in lite-c? or
Is it
a) VECTOR temp;
b) VECTOR* temp; ..... ?

Is there a scope where it is declared for either declaration syntax?

I've seen some sample codes using (a) and/or (b)...
I try to declare a global vector using (a), it works fine.
Then, i try also declaring a global vector using (b).. it crashes!

just for clarification. Thanks

Re: declaring Vector [Re: boyax] #270919
06/10/09 14:28
06/10/09 14:28
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Ive had great difficulties with the vector over time too.
To the best of my knowledge, which is far from perfect

Use version A when it is a local variable.

Use version B when it is a local or global POINTER, and is just going to point at other vectors. (uncommon)

Use version A when it is a global variable, but you dont care about its initial value. (dirty!)

Use version C when it is a global variable, and you want to set its initial value.
Version C is VECTOR* temp = { x=0; y=0; z=0; }


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: declaring Vector [Re: EvilSOB] #270920
06/10/09 14:52
06/10/09 14:52
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
In version a) you declare a vector. In version b) you declare not a vector, but an empty pointer. Using empty pointers in functions will CRASH. So, there is no sample code for b) unless you want to learn how to crash the engine.

Sample code for a:

function foo()
{
VECTOR v;
vec_set(v,vector(1,2,3));
vec_add(v,v);
...
}

and so on...

When you really want to use pointers, you must always let those pointers point to something... otherwise, CRASH!!

VECTOR* v; // empty pointer, points to nothing
vec_set(v,vector(1,2,3)); // crash!

but

VECTOR* v = { x = 0; y = 0; z = 0; } // now v points to a real vector
vec_set(v,vector(1,2,3)); // no crash!

Hope this helps..


Re: declaring Vector [Re: Tobias] #271056
06/11/09 03:56
06/11/09 03:56
Joined: Mar 2009
Posts: 276
Cebu City, Philippines
boyax Offline OP
Member
boyax  Offline OP
Member

Joined: Mar 2009
Posts: 276
Cebu City, Philippines
Thanks for the info. smile

Re: declaring Vectors [Re: Tobias] #271145
06/11/09 14:29
06/11/09 14:29
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline
User
Carlos3DGS  Offline
User

Joined: Oct 2008
Posts: 513
wow thans to both of you!
I was using mostly version b (dont know why it dosnt always crash), and when I did get a crash I would change to option a (but didnt understand why I had to do so).
Now I know why each one is used, thanks!


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: declaring Vectors [Re: Carlos3DGS] #271425
06/13/09 02:34
06/13/09 02:34
Joined: Apr 2009
Posts: 248
Philippines
seecah Offline
Member
seecah  Offline
Member

Joined: Apr 2009
Posts: 248
Philippines
Actually you can read all about this stuff at AUM 82 under PLUG and PLAY then lite-C pointers.. smile



Can't is not an option™

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

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