LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-30-2004, 03:57 AM   #1
xconspirisist
Member
 
Registered: Dec 2002
Location: United Kingdom
Distribution: Ubuntu
Posts: 276

Rep: Reputation: 30
Passing arg 3 of blah makes pointer from integer without a cast


I've been trying to resolve this for most of the day, and its really getting on my tits. I hope you guys can help.

This code that is about to be posted contains large chunks of the quake 3 source code. This code is freely avalible from ID Software, officially.

mkah. I've a class called ' ci '.

Code:
typedef struct {
	qboolean		infoValid;

	char			name[MAX_QPATH];
	team_t			team;

	int				botSkill;		// 0 = not bot, 1-5 = bot

	vec3_t			color1;
	vec3_t			color2;

	int				player;			// updated by player servercmds
	int				location;		// location index for team mode
	int				health;			// you only get this info about your teammates
	int				armor;
	int				curWeapon;

	int				handicap;
	int				wins, losses;	// in tourney mode

	int				teamTask;		// task in teamplay (offence/defence)
	qboolean		teamLeader;		// true when this is a team leader

	int				powerups;		// so can display quad/flag status

	int				medkitUsageTime;
	int				invulnerabilityStartTime;
	int				invulnerabilityStopTime;

	int				breathPuffTime;

	// when clientinfo is changed, the loading of models/skins/sounds
	// can be deferred until you are dead, to prevent hitches in
	// gameplay
	char			modelName[MAX_QPATH];
	char			skinName[MAX_QPATH];
	char			headModelName[MAX_QPATH];
	char			headSkinName[MAX_QPATH];
	char			redTeam[MAX_TEAMNAME];
	char			blueTeam[MAX_TEAMNAME];
	qboolean		deferred;

	qboolean		newAnims;		// true if using the new mission pack animations
	qboolean		fixedlegs;		// true if legs yaw is always the same as torso yaw
	qboolean		fixedtorso;		// true if torso never changes yaw

	vec3_t			headOffset;		// move head in icon views
	footstep_t		footsteps;
	gender_t		gender;			// from model

	qhandle_t		legsModel;
	qhandle_t		legsSkin;

	qhandle_t		torsoModel;
	qhandle_t		torsoSkin;

	qhandle_t		headModel;
	qhandle_t		headSkin;

	qhandle_t		modelIcon;

	animation_t		animations[MAX_TOTALANIMATIONS];

	sfxHandle_t		sounds[MAX_CUSTOM_SOUNDS];
} clientInfo_t;
Look at the datatypes of handicap, name, wins losses, for example.

In a function, in another file, I am using the class...

Code:
static void CG_DrawClient( score_t *player, qboolean largeFormat ) {
	char xc_handicap;
	char xc_winloss;
	char xc_name;
	char xc_ping;
	char xc_score;
	vec3_t	headAngles;
	clientInfo_t	*ci;

	ROW_Y = (ROW_Y + 32);
	ci = &cgs.clientinfo[player->client];
		
	xc_handicap = ci->handicap;
	xc_name = ci->handicap;
	xc_winloss = 10;// ci->wins ci->losses
	xc_ping = player->ping;
	xc_score = ci->handicap;

....
I am assigning the members of the class to variables.

Then using these variables in a function;

Code:
CG_DrawStringExt( HANDICAP_X, ROW_Y, xc_handicap, colorWhite, qfalse, qtrue,SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 0 );
And the function CG_DrawStringExt looks like this;

Code:
void CG_DrawStringExt( int x, int y, const char *string, const float *setColor, 		qboolean forceColor, qboolean shadow, int charWidth, int charHeight, int maxChars )
Then I get the following compile error, refuring the the 3rd code example;

warning; passing arg 3 of CG_DrawStringExt makes pointer from integer without a cast

This error occours with every use of the CG_DrawStringExt, using the xc_variables. I believe the problem is the datatypes. In the class, handicap is declared as an int, whereas in the 2nd code example, i am assigning it to char datatype. The CG_DrawStringExt function expects something else... I'm not sure.

Please help Many thanks.
 
Old 07-30-2004, 04:12 AM   #2
barisdemiray
Member
 
Registered: Sep 2003
Location: Ankara/Turkey
Distribution: Slackware
Posts: 155

Rep: Reputation: 30
Maybe you should try passing address of xc_handicap.. CG_DrawStringExt expects for an address..

CG_DrawStringExt( HANDICAP_X, ROW_Y, &xc_handicap, colorWhite, qfalse, qtrue,SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, 0 );

Also pay attention to the possibility of size mismatch and data loss when assignin an int to a char..
 
Old 08-21-2004, 11:40 AM   #3
xconspirisist
Member
 
Registered: Dec 2002
Location: United Kingdom
Distribution: Ubuntu
Posts: 276

Original Poster
Rep: Reputation: 30
I've fixed the above problem, many thanks.

As you can see in the following code ( also shown in my first post ), i am using variables named xc_ to drag bits of data from various classes ( ? ).

Code:
static void CG_DrawClient( score_t *player, qboolean largeFormat ) {
	char xc_handicap;
	char xc_winloss;
	char xc_name;
	char xc_ping;
	char xc_score;
	vec3_t	headAngles;
	clientInfo_t	*ci;

	ROW_Y = (ROW_Y + 32);
	ci = &cgs.clientinfo[player->client];
		
	xc_handicap = ci->handicap;
	xc_name = ci->handicap;
	xc_winloss = 10;// ci->wins ci->losses
	xc_ping = player->ping;
	xc_score = ci->handicap;

....
I am passing these xc_variables to cg_DrawStringExt function, shown in my first post. As you can see, the xc_ variables have the datatype ' char '.

The function 'cg_DrawStringExt' defines ' const char *string '. is the function converting the datatype or some weird thing, because it is spewing out random characters.
 
Old 08-21-2004, 11:42 AM   #4
xconspirisist
Member
 
Registered: Dec 2002
Location: United Kingdom
Distribution: Ubuntu
Posts: 276

Original Poster
Rep: Reputation: 30
looking at it a second time, I think I am experiencing the dataloss, mentioned earlier, when changing between and int and a char. can someone explain howto avoid this ? thanks.
 
Old 08-21-2004, 12:01 PM   #5
barisdemiray
Member
 
Registered: Sep 2003
Location: Ankara/Turkey
Distribution: Slackware
Posts: 155

Rep: Reputation: 30
Quote:
Originally posted by xconspirisist
looking at it a second time, I think I am experiencing the dataloss, mentioned earlier, when changing between and int and a char. can someone explain howto avoid this ? thanks.
int type is 2 or 4 bytes but a char is only a byte. So you should always cast a data at some type to a wider type to avoid data losses. But if your int type variable contains a data which has a size that can be holded by a char, then there won't be a problem at casting.
 
Old 08-22-2004, 06:18 AM   #6
xconspirisist
Member
 
Registered: Dec 2002
Location: United Kingdom
Distribution: Ubuntu
Posts: 276

Original Poster
Rep: Reputation: 30
Code:
char *xc_handicap;
by putting that star before xc_handicap, am i making a cast then ?
 
Old 08-22-2004, 08:04 AM   #7
Brane Ded
Member
 
Registered: Nov 2003
Location: over there
Distribution: Debian Testing
Posts: 191

Rep: Reputation: 30
Quote:
Originally posted by xconspirisist
Code:
char *xc_handicap;
by putting that star before xc_handicap, am i making a cast then ?
You're making a pointer. When you make a cast, your shoving the contents of a variable of one data type into the storage space of a varable of another data type. Sometimes it fits, and it can be usefull if it does, but sometimes it's like trying to put the square peg into the round hole. The data that doesn't fit gets trimmed off.

Last edited by Brane Ded; 08-22-2004 at 08:06 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing arg 3 of `pthread_create' from incompatible pointer type wallwaters Programming 8 03-08-2010 01:46 AM
What is the warning: passing arg 3 of `pthread_create' from incompatible pointer type wallwaters Linux - Software 3 06-01-2005 08:30 AM
makes pointer from integer without a cast ? hubabuba Programming 2 01-28-2005 05:28 PM
pointer from integer without a cast bcf2 Programming 7 12-30-2004 02:04 PM
makes pointer from interger without a cast y0shi Linux - General 4 10-21-2004 08:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration