具有不推荐使用的功能的V ++编译器错误(4996)和使用System :: Threading :: ThreadState(及其他!) [英] V++ compiler bug with Deprecated functions (4996) and use of System::Threading::ThreadState (and others!)

查看:93
本文介绍了具有不推荐使用的功能的V ++编译器错误(4996)和使用System :: Threading :: ThreadState(及其他!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VS2005/VS2008中出现的症状.

从.net1.1到.net2时,我得到一些奇怪的行为(请参阅选择"Windows Forms Application"

并将stdio.h包含下面的代码片段添加到test.cpp源文件.....

Symptoms exhibited in VS2005/VS2008.  see below for reproduction intructions.

I was getting some strange behaviour whilst moving from .net1.1 to .net2 (see Visual Studio 2005 has stopped warning about deprecated functions ) involving warning 4996: deprecated function, in this case, a 'sprintf' call, not being spotted if a reference to System::Threading::Threadstate was made.  I now believe this is a c++ compiler issue (which is why I've created this new question here...)

How To Reproduce
---------------------
in VS2005/VS2008, create a new c++ project called 'test'  (file|new|project)
select "Windows Forms Application"

and add the stdio.h include the code fragment below into the test.cpp source file.....

#include <stdio.h>

...
int main(array<System::String ^> ^args)
{
    int i;
    System::Threading::ThreadState state;

    char str[20];
    sprintf (str, "%s", "test string");

...


如果编译代码,则会收到有关未引用'i'和'state'的两个警告,但是如果注释掉SYstem :: Threading:Thread状态,则会收到有关'i'的警告.被未引用,并且正在关于sprintf语句的警告(C4996)....

在使用System :: Threading :: ThreadState时,为什么编译器没有发现已弃用的函数?  对于"System :: Windows :: Forms :: MessageBoxIcon","System :: Base64FormattingOptions"也是如此.以及所有枚举类"类型!

有人知道为什么会发生这种情况吗?



If you compile the code, you'll get two warnings about 'i' and 'state' being unreferenced, but if you comment out SYstem::Threading :Thread state, you'll get one warning about 'i' being unreferenced and the being the 'deprecated' warning (C4996) about the sprintf statement....

Why didn't the compiler spot the deprecated function when System::Threading::ThreadState was used?  This is also occurs for "System::Windows::Forms::MessageBoxIcon", "System::Base64FormattingOptions" and perhap all 'enum class' types!

Anyone know why this occurs?  Is there a fix for this situation?

推荐答案

如果我错了,请纠正我,但是为什么不使用sprintf_s,不建议使用.不推荐使用仅表示该功能不安全或可以使用更好的功能,我认为这不是错误,我可能是错误的.

Correct me if I'm wrong but why don't you use sprintf_s which is not deprecated. Deprecated just means that the function is unsafe or a better function is available I don't think it is bug, I might be wrong.

http://msdn.microsoft.com/en-us/library/ce3zzk1k%28VS.80%29.aspx

状态",因为未为其分配值. "i"也是如此,我在哪里被使用,它就在那里一个人.

'state' is unreferenced because it is not assigned a value. So is 'i', where is i being used it is just there all alone.


这篇关于具有不推荐使用的功能的V ++编译器错误(4996)和使用System :: Threading :: ThreadState(及其他!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆