c – 如何在不推荐使用的函数中添加字符串或消息
发布时间:2020-12-16 09:55:51 所属栏目:百科 来源:网络整理
导读:我有一个函数说void foo().我贬低就是 老功夫: – void foo()__attribute__ ((deprecated)); 新功能: – void FOO(); 现在我想在旧函数中添加一条消息,“使用的新函数是FOO”,可以看到编译代码后我们将得到的警告消息. 这该怎么做. 解决方法 您可以使用[[d
我有一个函数说void foo().我贬低就是
老功夫: – void foo()__attribute__ ((deprecated)); 新功能: – void FOO(); 现在我想在旧函数中添加一条消息,“使用的新函数是FOO”,可以看到编译代码后我们将得到的警告消息. 这该怎么做. 解决方法
您可以使用[[deprecated(msg)]]属性,这也是一种标准方法(从C 14开始).
[[deprecated("do not use")]] void f() {} int main(){ f(); } clang的输出: warning: 'f' is deprecated: do not use [-Wdeprecated-declarations] f(); ^ note: 'f' has been explicitly marked deprecated here void f() ^ 1 warning generated. 输出g: In function ‘int main()’: warning: ‘void f()’ is deprecated (declared at test.cpp:2): do not use [-Wdeprecated-declarations] f(); ^ warning: ‘void f()’ is deprecated (declared at test.cpp:2): do not use [-Wdeprecated-declarations] f(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |