程序是用ADO访问SQLSERVER的`
出现如下一个警告
d:\程序\debug\msado15.tlh(409):warning c4146,unary minus operator applied to unsigned type result still unsigned.急啊,,在线等,解决就给分!

解决方案 »

  1.   

    如果有下列的操作,就会有这个警告了
    unsigned int ui;
       -ui;        mdsn上面有解释When you compile an ActiveX Data Objects (ADO) application in Visual C++ 6.0 using the #import directive with version 2.5 or 2.6 of Msado15.dll, you may receive the following warning: warning C4146: unary minus operator applied to unsigned type, result still unsigned RESOLUTION
    Although this problem will most likely have no effect on your application, you can suppress the warning with the following code: 
    #pragma warning(push)
    #pragma warning(disable:4146)
    #import "c:\program files\common files\system\ado\MSADO15.DLL" 
    #pragma warning(pop) 这个警告对你的工程没什么影响,你用上述的做法就可以把这个警告禁住了
      

  2.   

    对,msdn里面已经说明了,这个警告没有什么影响,可以忽略。
      

  3.   

    handsomerun(毛毛)给的是正解!
    你可以将如下代码添加到stdafx.h文件里:
    #pragma warning(disable:4146)
    顺便说一下:该问题和SQL Server没有关系,使用ADO访问数据库都会出现次警告!
    微软解释如下:
    一元负运算符应用于无符号类型,结果仍为无符号类型无符号类型只能保存非负值,所以一元负(非)应用于无符号类型时通常无意义。操作数和结果都是非负的。实际上,当程序员试图表达最小整数值 -2147483648 时,发生此问题。该值不能写为 -2147483648,因为表达式处理分两个步骤: 计算数字 2147483648。因 2147483648 大于最大整数值 2147483647,所以其类型不是 int,而是 unsigned int。 
    将一元负应用于该值,得到无符号结果,该结果碰巧是 2147483648。 
    无符号类型的结果可能导致意外行为。如果在比较中使用该结果,则可使用无符号比较,例如另一个操作数是 int 时。这解释了下面的示例程序只输出一行的原因。预期的第二行为 1 is greater than the most negative int,但未输出,因为 ((unsigned int)1) > 2147483648 为假。可以通过从 Limits.h 使用 MIN_INT 来避免 C4146 警告,该 MIN_INT 有 signed int 类型。