错误消息警告C4244 [英] Error Message Warning C4244
本文介绍了错误消息警告C4244的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
收到有关数据类型的错误消息:
警告C4244:正在初始化":从"my_ulonglong"转换为"unsigned int",可能丢失数据
Receiving an error message on data type:
warning C4244: ''initializing'' : conversion from ''my_ulonglong'' to ''unsigned int'', possible loss of data
int main()
{
MYSQL_RES *res_set;
MYSQL* conn;
MYSQL_ROW row;
conn = mysql_init(NULL);
if (mysql_real_connect(conn,"urlock.db.5513143.hostedresource.com","VendorCheck","Reader1234","urlock",0,NULL,0) !=0)
{
mysql_query(conn,"SELECT * FROM tblURL WHERE ''192.168.1.1''");
unsigned int i = 0;
res_set = mysql_store_result(conn);
unsigned int numrows = mysql_num_rows(res_set);
while ((row = mysql_fetch_row(res_set)) != NULL){
printf("%s\n",row[i] != NULL ?
row[i] : "NULL");
}
mysql_free_result(res_set);
mysql_close(conn);
system("PAUSE");
}
else
{
cout << "Conn Failed!" <<endl;
system("PAUSE");
return 0;
}
}
推荐答案
mysql()
调用之一可能返回类型my_ulonglong
,通常类型"long long"的整数是64位整数,因此编译器告诉您,将"long long"整数的值放入常规的32位整数时,可能会丢失数据.如果您不希望结果超过32位整数的最大值,则只需执行显式强制转换以防止出现警告,否则,请将值传递给64位整数. br/>
显式演员表:
One of themysql()
calls is probably returning typemy_ulonglong
, usually a type "long long" integer is a 64-bit integer, so the compiler''s telling you that you may lose data when placing the value of a "long long" integer to a regular 32-bit integer. If you don''t expect the result to ever exceed the maximum value of a 32-bit integer, then just do an explicit cast to keep the warning from coming up, otherwise, pass the value onto a 64-bit integer instead.
Explicit Cast:
unsigned int val = (unsigned int) mysqlblah();
或将return int设置为64位int(两种选择):
Or set your return int to a 64-bit int (two alternatives):
unsigned long long val = mysqlblah();
unsigned __int64 val = mysqlblah();
这是参考页:
http://msdn.microsoft.com/en-us/library/s3f49ktz%28v = vs.80%29.aspx [ ^ ]
Here''s a reference page:
http://msdn.microsoft.com/en-us/library/s3f49ktz%28v=vs.80%29.aspx[^]
这篇关于错误消息警告C4244的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文