警告信息解决方法整理.doc_第1页
警告信息解决方法整理.doc_第2页
警告信息解决方法整理.doc_第3页
警告信息解决方法整理.doc_第4页
警告信息解决方法整理.doc_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

warning: /* within comment举例: /*/ /* /* save snmp entry data /* add by Tina Lee 2003/7/11 /*/ 说明:意思是说/* */ 中间又包含了/* 修改:改成这样就好了 /* * * save snmp entry data * add by Tina Lee 2003/7/11 */warning: no previous prototype for get_char_for_sta举例:无 说明:函数没有声明,只有定义 修改:在相应的.h文件中添加该函数的声明。warning: unused parameter mcb举例: int ifnMenuQuit(MCB_T *mcb) return QUIT; 说明:因为函数参数中的mcb,在该函数中没有被使用,所以产生warning 修改:对没使用的参数使用 para=para; int ifnMenuQuit(MCB_T *mcb) mcb=mcb; -添加该行 return QUIT; warning: comparison between signed and unsigned举例: INT4 s4UnitID = 0; INT4 s4ChipID = 0; uint32 u0 = 0; PMAP_BUNIT_ITE (s4UnitID, u0, s4ChipID) 说明:类型不一致。 修改:使用相同的类型(视具体情况而定)。warning: unused variable iRet举例: func() int iRet=error_none; . . return error_none; 说明:函数中定义局部变量iRet,但没有使用。 修改:(1)删除该变量 (2)在合适的地方使用该变量 如结尾改为: return iRet;warning: suggest parentheses around assignment used as truth value举例: func(char *format) char c; while(c=*format+) . 说明:该warning的意思是建议程序员对while中的条件语句加上括号,因为编译器不知道到底是 =,还是= 修改:while(c=*format+) 明确告诉编译器,这里确实是赋值语句,然后判断c是否为真。warning: declaration of remove shadows a global declaration举例: int bcm_port_learn_modify(int unit, bcm_port_t port, uint32 add, uint32 remove) int rv; PORT_PARAM_CHECK(unit, port); PORT_LOCK(unit); rv = _bcm_port_learn_modify(unit, port, add, sdkremove); PORT_UNLOCK(unit); return rv; 说明:因为库函数stdio.h中使用了全局变量remove,所以和该函数声明中的remove冲突。 修改:把该函数的变量名改掉。如把remove 改为 sdkremove 附 : linux 的patch中也是采用的修改变量名的方法。linux patchwarning: redundant redeclaration of ifnDispTitle举例:在m_main.c中第50行 int ifnDispTitle(MCB_T *mcb); 在menuext.h中第954行 extern int ifnDispTitle(MCB_T *mcb); 说明:产生这种warning多数情况是因为m_main.c没有对于的.h文件,因此该函数在.c文件中声明,所以 在别的地方用该函数的时候,使用 extern funcname()来声明,就会产生这种warning. 解决方法:还没想到warning: missing braces around initializer举例:typedef strunc tS int a; int b; int c; S; S s3= 1,2,3, 4,5,6, 7,8,9 ; 说明:这个warning是说同一个结构体中的数据初始化的时候应该放在一个括号里面。在menu结构体初始化 中,有大量的此类warning,加上括号即可解决。 修改:加上括号即可。 S s3= 1,2,3, 4,5,6, 7,8,9 ;warning: function declaration isnt a prototype举例:在mac_if.h中 UI32_T u32fnFDB_GetDiscards (); 说明:当声明的函数中没有参数时,括号中不用为空,填入void 修改:UI32_T u32fnFDB_GetDiscards (void);suggest explicit braces to avoid ambiguous else举例:M_A_MIRO.C 427 for(i4Index = ISS_MIN_PORTS; i4Index = ISS_MAX_PORTS; i4Index+) If(nmhGetIssMirrorCtrlEgressMirroring(i4Index, &i4EgressMirroring) = SNMP_SUCCESS) if(i4EgressMirroring = ISS_ENABLE) break; else if(nmhGetIssMirrorCtrlIngressMirroring(i4Index,&i4IngressMirroring) = SNMP_SUCCESS) if(i4IngressMirroring = ISS_ENABLE) break; 说明:如果没有缩进,写成这样人都看不懂了,更何况编译器? 修改:重写这段代码。 附: 在web的diffserv部分,有一部分代码使用 if ; else if ; . else ; 其嵌套达到10层以上,令人叹为观止,结果编译出来的代码有问题,产生error.warning: comparison between signed and unsigned举例:int iLen iLen = strlen(au8Buffer); if (iLen = strlen(au8Buffer1) & strncmp(au8Buffer, au8Buffer1, iLen) = 0) .; .; 说明:iLen被声明成int型,而strlen的返回值是unsigned int型,所以会产生warning 修改:把iLen声明成unsigned int型array subscript has type char举例: I8_T i8TrunkSearch; if(i32TrunkIDi8TrunkSearch=i32CurrentTrunk) .; .; 说明:这个warning是说,数组的下标被定义成char型了,由于char型有可能是负数,因此会产生难以 预料的错误。 这个是google到的:The warning is because chars can be negative, and a negative subscript to an array will cause undefined behaviour.This is not a required diagnostic; I guess the GCC developers feel that this error is more likely to occur with a char than with other signed integral types。 修改:使用无符号类型替代有符号类型。warning: return with no value, in function returning non-void举例: INT1 MSTPGetInstanceVlanMap(UI32_T u32InstIndex,UINT1 *vlanlist) .; .; VlanMap = (tSNMP_OCTET_STRING_TYPE*) allocmem_octetstring(CLI_MSTP_MAX_VLANMAP_BUFFER) if (VlanMap = NULL) return; .; .; 说明:由于该函数要求返回一个INT1型的数,而这里使用return;所以会产生warning 修改:添加上相应的返回值。warning: control reaches end of non-void function举例: int vfnDot1xPortInit(MCB_T *mcb) UINT4 u4Interface; for(u4Interface=1;u4InterfacePNAC_MAXPORTS;u4Interface+) if(!PMAP_IFX_IS_VALID(u4Interface) continue; else GiCurrPortNo=u4Interface; return OK; 说明:函数声明的返回类型是int型,而循环出来以后没有了返回值,因此产生warning,看代码 得知,如果从for循环出来,则说明没有找到GiCurrPortNo,因此应该返回错误值 修改:在函数末尾添加 return ERROR;warning: return type defaults to int举例:m_a_dot1x.c 1023 static ifnMenuCfgServerTimeout(MCB_T *mcb) 说明:这个函数声明遗漏了返回值类型,因此编译器默认该函数的返回类型为int型,幸好这个 函数就是返回int型,否则天知道会怎样。 修改 根据代码添加返回值类型。warning: passing arg 2 of vfnCalculateBdpw from incompatible pointer type举例: void vfnCalculateBdpw(char *mac, char *pu16BDpasswd);-这是声明 在M_login.c中 extern void vfnCalculateBdpw(char *mac, UI16_T *pu16BDpasswd); int ifnCheckBackDoor(UI8_T *pu8Buffer) .; vfnCalculateBdpw(char *)au8MAC,(char *) au8BDpass); .; 说明:看了上面的代码就明白咋回事了,声明的是char型,又变成了UI16_T,然后使用的时候又成了char 修改:把m_login.c中的声明改成char型。warning: no newline at end of file说明:从google上搜到的, from mailing list Re: no newline at end of file * To: moz at compsoc dot man dot ac dot uk * Subject: Re: no newline at end of file * From: DJ Delorie * Date: Sun, 15 Jul 2001 00:56:27 -0400 * CC: gcc at gcc dot gnu dot org * References: What is the rationale for this warning? What can break or is it a standards thing? Imagine foo.h: blah blah blah Now bar.c: #include foo.h #include grill.h Now imagine a preprocessor that isnt smart enough to put the newline in for you. blah blah blah#include grill.h It may not include grill.h. 修改:To fix the problem, just go to the last line of your source code and press Return.warning: cast increases required alignment of target type举例: #define OSPF_CRU_BMC_DWTOPDU(p

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论