When I’m trying to compile this code with gcc version 4.6.3 on linux with -Wall flag I’m getting these two warnings:
-
It points to
cmd[1]=cmd2send;warning: assignment makes pointer from integer without a cast [enabled by default]
-
It points to the variable
static unsigned char *cmd[65]warning: variable ‘cmd’ set but not used [-Wunused-but-set-variable].
What makes these warnings? and how to avoid them?
int CommandHandler(unsigned char cmd2send)
{
static unsigned char *cmd[65];
// *make sure device is open*
if(handle==NULL) // handle defined in transceiver.h
{
puts("CommandHandler::Cant handle command");
// try to open device again
if(OpenMyDev()!=0)
return -1;
// if no return then retry is fine
puts("retry SUCCEEDED!, device is open");
}
// *send command to firmware*
cmd[0]=0x0;
cmd[1]=cmd2send;
.......
return 0;
}
Here, also I’m getting warning #2 for variable voltage:
float Get_Temperature(void)
{
//unsigned char RecvByte=0;
//int byte[4];
int i;
float voltage=0;
float resistance=0;
float temperature=0;
float SamplesAVG=0;
unsigned int Samples=0;
unsigned char* rvc;
unsigned char mydata[65];
for(i=0;i<=10;i++)
{
//Transimit Start Of Frame
mydata[0]=0;
mydata[1]=GET_TEMPERATURE;
if(Write2MyDev(mydata)<0) {return -1;}
rvc=ReadMyDev(0);
SamplesAVG+=(rvc[0]<<24)+(rvc[1]<<16)+(rvc[2]<<8)+rvc[3];
usleep(100*1000);
}
Samples=SamplesAVG/10;
printf("TO PRINT VAL:%d\n",Samples);
puts("------------");
voltage = (Samples * 5.0)/1023.0; // 0..1203= 1024 values
resistance = 10000.0/ (1023.0/Samples);
...
return retval;
}
cmd2sendis anunsigned charand you are setting the value atcmd[1]which is achar *to it. Achar *is a pointer and anunsigned charis treated like an integer so you are making a pointercmd[1]from anintegerwithout a cast.Chances are you wanted an array of characters
char cmd[65]not an array ofchar *Also since you created and assigned values to
cmdbut you never use it you get a warning for that as well.