类型转换中的截断问题!
我调用一个函数
acsEnumServerNames(ST_CSTA, AddToList, (unsigned long)m_TserverList);
其中char m_TserverList[40];
acsEnumServerNames的函数声明如下:
RetCode_t acsEnumServerNames(
StreamType_t streamType,
EnumServerNamesCB callback,
unsigned long lParam);
但是在编译的时候,m_TserverList 的类型转换有一个告警
warning C4311: “类型转换” : 从“char *”到“unsigned long”的指针截断。
请教如何消除这个告警。
问题点数:20、回复次数:3Top
1 楼li_qingsong(铭心)回复于 2003-06-03 13:13:43 得分 10
使用atol()先转换数据,然后再调用acsEnumServerNames()就ok!啦
Top
2 楼li_qingsong(铭心)回复于 2003-06-03 13:14:10 得分 10
例如:
#include <stdlib.h>
#include <stdio.h>
void main( void )
{
char *s; double x; int i; long l;
s = " -2309.12E-15"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );
s = "7.8912654773d210"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );
s = " -9885 pigs"; /* Test of atoi */
i = atoi( s );
printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );
s = "98854 dollars"; /* Test of atol */
l = atol( s );
printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
}
Output
atof test: ASCII string: -2309.12E-15 float: -2.309120e-012
atof test: ASCII string: 7.8912654773d210 float: 7.891265e+210
atoi test: ASCII string: -9885 pigs integer: -9885
atol test: ASCII string: 98854 dollars long: 98854
Top
3 楼blestrabbit(这个兔子有点稚气有点呆有点可爱有点帅)回复于 2003-06-04 09:44:36 得分 0
我是将m_TserverList的地址值给传进函数调用,用unsigned long应该没有问题的,为什么会出现截断的告警?Top




