Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 801 guests, and 6 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
Little problem with pointer #313792
03/03/10 17:28
03/03/10 17: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
I have a small(?) problem here:

Code:
typedef struct
{
	VECTOR3D n;
	float d;
} Plane;

typedef struct
{
	Plane* plane;
	int size;
} VecPlane;

void planesSetSize(VecPlane* p, const int csize)
{
	if (p != NULL)
	{
		if (csize != p->size)
		{
			*p->plane = (Plane*)realloc(p->plane, csize*sizeof(Plane));
			*p->size = csize;
		}
	}
}



when compiling i get
Quote:
"can not convert 'POINTER' to 'struct Plane'"

for *p->plane = (Plane*)realloc(p->plane, csize*sizeof(Plane));

and
Quote:
illegal indirection

for *p->size = csize;


Tried a lot of combinations with () and * but so far none worked wink

Any help appreciated laugh


Shade-C EVO Lite-C Shader Framework
Re: Little problem with pointer [Re: BoH_Havoc] #313795
03/03/10 17:36
03/03/10 17:36
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Code:
*p->plane = (Plane*)realloc(p->plane, csize*sizeof(Plane));
*p->size = csize;


I think this is your problem. You dereference the pointer, and then use the 'member-by-pointer' operator, when you really want a 'member-by-variable'. So just remove the * ...
Code:
p->plane = (Plane*)realloc(p->plane, csize*sizeof(Plane));
p->size = csize;

or

(*p).plane = (Plane*)realloc(p->plane, csize*sizeof(Plane));
(*p).size = csize;



Last edited by DJBMASTER; 03/03/10 17:38.
Re: Little problem with pointer [Re: DJBMASTER] #313798
03/03/10 17:43
03/03/10 17:43
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
HMmm...but if i remove the *, will the original p be altered ?



VecPlane orgP;
planesSetSize(orgP, 10);

is orgP = p from the function now? *scratches his head*


thanks for the quick reply laugh




Shade-C EVO Lite-C Shader Framework
Re: Little problem with pointer [Re: BoH_Havoc] #313802
03/03/10 17:57
03/03/10 17:57
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
In the snippet you posted, no, because it wants a pointer to a struct, not the struct itself, so it probably wont even compile.

Your original code is fine it's just you've got a syntax error. You can't use *a->b because -> gets the member b from the pointer a, and so by derefencing it, you are turning a into the variable, where -> fails.

All this pointer stuff gets confusing after a while, but I think your code is correct except for those 2 lines I posted earlier, where you are mixing * with ->.

Last edited by DJBMASTER; 03/03/10 17:59.
Re: Little problem with pointer [Re: DJBMASTER] #313845
03/03/10 22:21
03/03/10 22:21
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
Yeah, DJBMASTER is right here: use the two code lines posted by him.

"HMmm...but if i remove the *, will the original p be altered ?"
Yes. In lite-C you can't pass structs by value, so p still points to your original struct.

"VecPlane orgP;
planesSetSize(orgP, 10);"

lite-C is supposed to differentiate between objects and pointers automatically (unless you set PRAGMA_POINTER). However, to be on the safe side you should use the address operator here: planesSetSize(&orgP, 10)

Re: Little problem with pointer [Re: Saturnus] #313996
03/04/10 21:42
03/04/10 21:42
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
Alrighty, thanks a bunch guys! 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