当我尝试在带有-Wall
标志的 linux 上使用 gcc 版本 4.6.3 编译此代码时,我收到以下两个警告:
它指向
cmd[1]=cmd2send;
警告:赋值使指针从整数而不进行强制转换[默认启用]
它指向变量
static unsigned char *cmd[65]
警告:变量 'cmd' 已设置但未使用 [-Wunused-but-set-variable]。
是什么导致了这些警告?以及如何避免它们?
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;
}
在这里,我也收到关于可变电压的警告 #2:
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;
}