Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (alibaba, vicknick), 1,492 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
typedef and arrays - typedef var myVar[x] #314004
03/04/10 22:28
03/04/10 22:28
Joined: Jun 2004
Posts: 655
to your left
BoH_Havoc Offline OP
User
BoH_Havoc  Offline OP
User

Joined: Jun 2004
Posts: 655
to your left
Another day, another problem wink

In C and lite-c i can create a new vartype by writing
Code:
typedef var myvar;



Now if i want to create a new array var type, in C i would write
Code:
typedef var myVar[x]; //x = any number



but in lite-c this doesn't work, i get a syntax error.
Any help? laugh


Shade-C EVO Lite-C Shader Framework
Re: typedef and arrays - typedef var myVar[x] [Re: BoH_Havoc] #314009
03/04/10 22:45
03/04/10 22:45
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Manual:
typedef can be used to redefine variables and structs; it can not be used for arrays and predefined engine objects.


Click and join the 3dgs irc community!
Room: #3dgs
Re: typedef and arrays - typedef var myVar[x] [Re: BoH_Havoc] #314010
03/04/10 22:46
03/04/10 22:46
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
Yeah, that's how it's supposed to work in C. Have you tried tpyedef var *mypvar;? Just curious, I've currently no A7 installed.

edit: you could still use #defines, but I'm sure you know that.

Last edited by Joey; 03/04/10 22:46.
Re: typedef and arrays - typedef var myVar[x] [Re: Joey] #314012
03/04/10 23:09
03/04/10 23:09
Joined: Jun 2004
Posts: 655
to your left
BoH_Havoc Offline OP
User
BoH_Havoc  Offline OP
User

Joined: Jun 2004
Posts: 655
to your left
Code:
Manual:
typedef can be used to redefine variables and structs; it can not be used for arrays and predefined engine objects.



Grrr...i'd have to rewrite 1300 lines of code then.

Quote:
Have you tried tpyedef var *mypvar;? Just curious, I've currently no A7 installed.

That somehow works, but i get an error when doing something like this (pointer confusion for the win!):

Code:
typedef var *VECTOR3D;

void linCombVECTOR3(VECTOR3D *mresult, const VECTOR3D pos,
	const VECTOR3D dir, const var t)
{
	mresult[0] = pos[0] + t*dir[0];
	mresult[1] = pos[1] + t*dir[1];
	mresult[2] = pos[2] + t*dir[2];
}


Quote:
Syntax error 'can't convert CONV:DOUBLE:POINTER'



Quote:
edit: you could still use #defines, but I'm sure you know that.

Nope, how to do it? laugh


Shade-C EVO Lite-C Shader Framework
Re: typedef and arrays - typedef var myVar[x] [Re: BoH_Havoc] #314013
03/04/10 23:18
03/04/10 23:18
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Maybe if you explain what you want, we can offer different solutions?
There's things like memory allocation for dynamic arrays...


Code:
mresult[0] = pos[0] + t*dir[0];


mresult is a double pointer, first in typedef and then in the arguments, while pos is only in the typedef. You can't make that conversion.

(mresult[0])[0] will probably work

Last edited by Joozey; 03/04/10 23:20.

Click and join the 3dgs irc community!
Room: #3dgs
Re: typedef and arrays - typedef var myVar[x] [Re: Joozey] #314014
03/04/10 23:25
03/04/10 23:25
Joined: Jun 2004
Posts: 655
to your left
BoH_Havoc Offline OP
User
BoH_Havoc  Offline OP
User

Joined: Jun 2004
Posts: 655
to your left
I have 1300 lines of code to generate the matrix for lispSM shadows and i'm trying to convert it to lite-c to spice up my shadows.

I'd like to define
typedef float VECTOR3D[3];
and
typedef VECTOR3D VECTOR3x8D[8];

as they are used all over the code. Now i could rewrite the whole code (change [0] with .x [1] with .y etc, create a struct for the VECTOR3x8D thingy, change code accordingly, etc. pp) or i could try to somehow get this working laugh

Even if not using it for the lispSM thing, i'm generally interisted in how to define a new type of array in lite-c as i think this is a nice thing to have laugh

[edit] tried it with (mresult[0])[0] and this seems to work (at least i get no errors on compiling). Have to test it a little more. Thanks so far! laugh

I'm still interisted in the #define method by Joey though


Shade-C EVO Lite-C Shader Framework
Re: typedef and arrays - typedef var myVar[x] [Re: BoH_Havoc] #314045
03/05/10 10:43
03/05/10 10:43
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
Code:
(*mresult)[0] =  = pos[0] + t*dir[0];


is cleaner, that's how you dereference pointers (although it's basically the same).

since c is pretty eager to convert everything correctly, you could try something like this:
Code:
typedef float *PVECTOR3D;
#define VECTOR3D float[3]

void myfunc(PVECTOR3D pos)
{
    pos[0] = ...
}
...

VECTOR3D mypos;
myfunc(mypos);


what won't work, though, is returning such a VECTOR3D, all it will do is return a pointer to a local variable on the stack which will vanish after the function returns. with typedef'ed variables you'll actually get a copy back. what could work, though, is something like
Code:
typedef struct { float x, y, z; } VECTOR3D;
#define _V(x) (float*)(&(x))

VECTOR3D mypos;
_V(mypos)[0] = ...
return mypos;


but then you could as well just use a struct directly. by the way, what you can do is
Code:
typedef struct { float[3][8] data; } VECTOR3Dx8D;
VECTOR3Dx8D mymatrix;
mymatrix.data[0][1] = ...
return mymatrix;


or, even more elegant, something like
Code:
typedef struct {
    union {
        float[2][2] data;
        struct {
            float xx, xy, yx, yy;
        };
    };
} MAT2x2;


might not work with lite-c, though, unnamed union members don't work in all c compilers.



Last edited by Joey; 03/05/10 10:50. Reason: found something elegant
Re: typedef and arrays - typedef var myVar[x] [Re: Joey] #314245
03/06/10 23:12
03/06/10 23:12
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Originally Posted By: Joey
but then you could as well just use a struct directly. by the way, what you can do is
Code:
typedef struct { float[3][8] data; } VECTOR3Dx8D;
VECTOR3Dx8D mymatrix;
mymatrix.data[0][1] = ...
return mymatrix;


should be?
Code:
typedef struct { float data[3][8]; } VECTOR3Dx8D;



Re: typedef and arrays - typedef var myVar[x] [Re: MrGuest] #314300
03/07/10 14:41
03/07/10 14:41
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
of course.

Re: typedef and arrays - typedef var myVar[x] [Re: Joey] #315160
03/13/10 16:07
03/13/10 16:07
Joined: Jun 2004
Posts: 655
to your left
BoH_Havoc Offline OP
User
BoH_Havoc  Offline OP
User

Joined: Jun 2004
Posts: 655
to your left
thx for the help, makes things a little easier for me laugh


Shade-C EVO Lite-C Shader Framework

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