首页 > 其他分享 >'function': was declared deprecated

'function': was declared deprecated

时间:2023-07-31 12:34:46浏览次数:41  
标签:function declared SECURE deprecated C4996 warning compiler



1. 警告消息 'function': was declared deprecated
Compiler Warning (level 1) C4996




Error Message

'function': was declared deprecated




The compiler encountered a function that was marked with deprecated. The function may no longer be supported in a future release. You can turn this warning off with thewarning pragma (example below).

C4996 is generated for the line on which the function is declared and for the line on which the function is used.

You will see C4996 if you are using members of the <hash_map> and <hash_set> header files in the std namespace. SeeThe stdext Namespace for more information.

Some CRT and Standard C++ Library functions have been deprecated in favor of new, more secure functions. For more information on deprecated functions, seeSecurity Enhancements in the CRT andSafe Libraries: Standard C++ Library.

C4996 can also occur if you use MFC or ATL functions that were deprecated for security reasons. To suppress these warnings, see_AFX_SECURE_NO_WARNINGS and_ATL_SECURE_NO_WARNINGS.



The following sample generates C4996.



// C4996.cpp
// compile with: /W1
// C4996 warning expected
#include <stdio.h>

// #pragma warning(disable : 4996)
void func1(void) {
   printf_s("\nIn func1");
}

__declspec(deprecated) void func1(int) {
   printf_s("\nIn func2");
}

int main() {
   func1();
   func1(1);
}


C4996 can also occur if you do not use a checked iterator when compiling with _SECURE_SCL 1. SeeChecked Iterators

The following sample generates C4996.




// C4996_b.cpp
// compile with: /EHsc /W1
#define _SECURE_SCL 1
#include <algorithm>
using namespace std;
using namespace stdext;
int main() {
   int a [] = {1, 2, 3};
   int b [] = {10, 11, 12};
   copy(a, a + 3, b);   // C4996
   copy(a, a + 3, checked_array_iterator<int *>(b, 3));   // OK
}



2. 消除的几种方法(不建议正式的项目中使用,只是用于自己做的一些小工具项目)


_SCL_SECURE_NO_WARNINGS 


Calling any one of the potentially unsafe methods in the Standard C++ Library will result inCompiler Warning (level 1) C4996. To disable this warning, define the macro_SCL_SECURE_NO_WARNINGS in your code:





2.1 #define _SCL_SECURE_NO_WARNINGS





 Remarks


Other ways to disable warning C4996 include:

  • 2.2 Using the /D (Preprocessor Definitions)compiler option:



    cl /D_SCL_SECURE_NO_WARNINGS [other compiler options] myfile.cpp

  • 2.3 Using the /w compiler option:



    cl /wd4996 [other compiler options] myfile.cpp

  • 2.4 Using the #pragma warning directive:



    #pragma warning(disable:4996)

Also, you can manually change the level of warning C4996 with the /w<l><n> compiler option. For example, to set warning C4996 to level 4:



2.5 cl /w44996 [other compiler options] myfile.cpp



3. 遇到一个链接错误 unresolved external symbol "const type_info::`vftable'" (??_7type_info@@6B@)


The symbol is defined in msvcrt.lib. You are not linking with that library because you specified the /NODEFAULTLIB linker option. Either remove that option, or add msvcrt.lib as an input library. Thanks for taking the time to report this!



Mitchell Slep


Visual C++ Compiler Team



RTTI is on by default in Visual C++ 2005, so you need to explicitly disable it by adding /GR- to the command line.



Thank you,



Dean Wills


Visual C++ Team



标签:function,declared,SECURE,deprecated,C4996,warning,compiler
From: https://blog.51cto.com/u_16156420/6907023

相关文章

  • kernel: oracle (xxxx): Using mlock ulimits for SHM_HUGETLB is deprecated
    Oracle数据库运行在linux6/7中,启用大页之后,我们经常在/var/log/messages里面会看到类似这样的记录:Jul3109:46:27p1erpdb01kernel:oracle(6444):UsingmlockulimitsforSHM_HUGETLBisdeprecated.-------官方文档HowToAddanon-rootgrouptohugetlb_shm_grou......
  • Python编码错误:no encoding declared
    问题描述Python文件中如果未指定编码,在执行过程会出现报错:....,butnoencodingdeclared....问题原因Python中默认的编码格式是ASCII格式,在没修改编码格式时无法正确打印汉字,所以在读取中文时会报错。Python3.X源码文件默认使用utf-8编码,所以可以正常解析中文,无需指定......
  • FUNCTION security.to_date does not exist
    方法函数不存在解决:oracle中说明使用的to_date不存在或当前版本不支持,换成to_days就可以了如果是mysql中,mysql并不支持to_date方法,所以需要改为str_to_date方法 或修改select*fromas_gen_plan_recordtwhereDATE_FORMAT(t.time,'%Y-%m-%d')>=DATE_FORMAT(:begi......
  • 【Oracle】 管道函数pipelined function简单的使用
    Oracle管道函数pipelinedfunction简单的使用如果在函数(function)中加关键字pipelined,就表明这是一个oracle管道函数,其返回值类型必为集合,体现出来的数据结构类似于表,即可以理解成,使用管道函数可以返回一张查询表,可以是单行数据也可以是多行数据,而不是平常函数返回的单行数据......
  • 关于TypeScript中提示xxx is declared but its value is never read的解决方法
    首先,提示很明显,是定义了变量,但是却没有使用。解决方案有如下两种: 一:需要确定变量是否真的没有使用到,如果没有使用直接删除即可。 二:对于方法中的入参,是没法随便删除的。这时候我们可以利用TypeScript4.2中的新特性,将变量名用下划线开头,表示占位变量。更具体的详情可......
  • 30 天精通 RxJS (02):Functional Programming 基本观念
    FunctionalProgramming是Rx最重要的观念之一,基本上只要学会FP要上手Rx就不难了!FunctionalProgramming可以说是近年来的显学,各种新的函式编程语言推出之外,其他旧有的语言也都在新版中加强对FP的支持!什么是FunctionalProgramming?FunctionalProgramming是一种编程......
  • typescriptfunction
    如何实现"typescriptfunction"整体流程为了实现"typescriptfunction",我们需要经历以下几个步骤:步骤描述步骤一安装TypeScript步骤二创建项目文件夹步骤三初始化TypeScript配置步骤四编写TypeScript代码步骤五编译TypeScript代码步骤六运行TypeScr......
  • @FunctionalInterface是必须的吗
    我的疑惑来源于源码中的函数式接口没有加@FunctionalInterface也可以支持lambda表达式例如RedisTemplate的源码:@OverridepublicBooleanexpire(Kkey,finallongtimeout,finalTimeUnitunit){byte[]rawKey=rawKey(key);longrawTimeout=Tim......
  • 超级好用的绕过php的disable_functions
    寻思寻思今天就写了吧这里背景是在打同学搭的网站,一句话已经进去了,但是执行不了命令 能够看到能用的函数几乎都被禁了在网上找了挺多方法都用不了,蚁剑的各种插件也绕不过最后找到了这个 哥斯拉的绕过disable中的双链表它的说法是这样的 (来源:http://www.hackdig.com/......
  • vue 父向子通过props 传递一个function报未定义
    解决方法:参考资料:https://cloud.tencent.com/developer/ask/sof/523570来自为知笔记(Wiz)......