User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 14 Jan 2003, 16:14   #1
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
Pointer problem...

I'm trying to pass a void pointer with a function so I can use sprintf to put it in a string. Problem is that I cannot get the value behind the pointer:

Code:
void Game3D::setParam(char* filename, char* preset, void* value, char type)
{
	char ln[100];
	char newline[100];

	sprintf(ln,"%s %%%c",preset,type);	//result: NEWLINE = <preset> %<type>
	sprintf(newline,ln,*value);			//result: NEWLINE = NEWLINE, with %<type> replaced

	MSGBOX(newline);
The second sprintf causes the problem, where I try to get the value behind the value pointer. This syntax gives an "illegal indirection" error. If I leave the '*' out I get the address of the pointer.

Anyone know how I can make this work? The value behind the pointer can be a bool, float or int.
Structural Integrity is offline   Reply With Quote
Unread 14 Jan 2003, 16:43   #2
Pitchfork
Tourist
 
Join Date: Jun 2001
Location: moon
Posts: 90
Pitchfork is an unknown quantity at this point
I think, u have to cast value depending on type:

like:
if(type == "f") sprintf(newline,ln,*((double*)value));
else if(type == ...
__________________
Quote:
Originally posted by Bloomers III
sex is dirty and for losers who can't masturbate properly
Pitchfork is offline   Reply With Quote
Unread 15 Jan 2003, 10:15   #3
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: Pointer problem...

Quote:
Originally posted by Structural Integrity
I'm trying to pass a void pointer with a function so I can use sprintf to put it in a string. Problem is that I cannot get the value behind the pointer:

Code:
void Game3D::setParam(char* filename, char* preset, void* value, char type)
{
	char ln[100];
	char newline[100];

	sprintf(ln,"%s %%%c",preset,type);	//result: NEWLINE = <preset> %<type>
	sprintf(newline,ln,*value);			//result: NEWLINE = NEWLINE, with %<type> replaced

	MSGBOX(newline);
The second sprintf causes the problem, where I try to get the value behind the value pointer. This syntax gives an "illegal indirection" error. If I leave the '*' out I get the address of the pointer.

Anyone know how I can make this work? The value behind the pointer can be a bool, float or int.
Can you not just create 3 overloaded functions changing void* value to bool*, float*, int* and then hope it picks up the right one?
pablissimo is offline   Reply With Quote
Unread 15 Jan 2003, 16:30   #4
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
I don't think overloading would be wise... my Game3D file is cluttered enough as it is.
Instead, I made a switch for the int and float and two different sprintf's and used the casting idea of Pitchfork.
The only problem I have now is a boolean. I used to pass them as an unsigned int and hoped that they are converted properly in the read variant of this function, but it appears this doesn't work in this case. It make a 0xffff of the bool, regardless of the value. Any ideas for this? Is there a conversion string ("%b" or so) for a boolean? My book doesn't list it.
Structural Integrity is offline   Reply With Quote
Unread 15 Jan 2003, 16:39   #5
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Another switch and a temp var storing an int value of 0 or 1? Then %d that...
pablissimo is offline   Reply With Quote
Unread 15 Jan 2003, 17:15   #6
Pitchfork
Tourist
 
Join Date: Jun 2001
Location: moon
Posts: 90
Pitchfork is an unknown quantity at this point
bool is defined via:
typedef int BOOL;
so at a quick look you should simply treat them as int
__________________
Quote:
Originally posted by Bloomers III
sex is dirty and for losers who can't masturbate properly
Pitchfork is offline   Reply With Quote
Unread 15 Jan 2003, 17:29   #7
queball
Ball
 
queball's Avatar
 
Join Date: Oct 2001
Posts: 4,410
queball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so little
sprintf("%s", *(BOOL *)value ? "верно" : "Не верно")?
queball is offline   Reply With Quote
Unread 15 Jan 2003, 18:58   #8
Cyp
∞+♪˛
 
Join Date: Nov 2000
Location: :uo!te]oŻ|
Posts: 428
Cyp is an unknown quantity at this point
Quote:
Originally posted by queball
sprintf("%s", *(BOOL *)value ? "верно" : "Не верно")?
I've actually been wondering why MSVC doesn't seem to compile unicode .cpp files.

Think it's silly not being able to use variable names such as &theta; and &Delta;x.
__________________
Structural Integrity for Creator - since he'll probably make PA turn 3D.
Wikipedia forum
Note to self - Don't write Chinese letters with bold and italics...
<!--Last incarnation: Nov 2000-->
Cyp is offline   Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 06:10.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018