如何检测使用的编译器 [英] How to detect the compiler used

查看:117
本文介绍了如何检测使用的编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个用VC6编译的程序,现在我要移至2005年,并且对某些函数调用(例如strcpy,wcscpy等)有一些已弃用的警告,我读到我需要为每个原因添加_s是安全的.净额.

我需要检测是否要为该程序使用VC6或.Net编译器,以便使用安全功能或旧功能.


谢谢,
Guillermo.

Hi,

I have a program which I compiled in VC6, I am moving to 2005 now, and have some deprecated warnings for some function calls like (strcpy, wcscpy, etc.) which I read I need to add _s to each cause is secure for .net.

What I need is to detect if I''m using the VC6 or .Net compiler for the program, in order to use the secure function or the old one.


Thanks,
Guillermo.

推荐答案



看看这个链接.宏"_MSC_VER"可能对您有用.

http://msdn.microsoft.com/en-us/library/b0084kay% 28VS.80%29.aspx [ ^ ]
Hi,

have a look at this link. The Macro "_MSC_VER" might be usefull for you.

http://msdn.microsoft.com/en-us/library/b0084kay%28VS.80%29.aspx[^]


看看PE/COFF格式规范:

http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx [^ ]

可选标头"(对于Windows PE不是可选的)包含可用于比较的MajorLinkerVersion和MinorLinkerVersion.

http://msdn.microsoft.com/en-us/library/ms680339(VS .85).aspx [ ^ ]

最好的祝福,
-David Delaune
Have a look at the PE/COFF format specification:

http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx[^]

The "Optional Header" (which is not optional for Windows PE) contains a MajorLinkerVersion and MinorLinkerVersion which can be used for comparison.

http://msdn.microsoft.com/en-us/library/ms680339(VS.85).aspx[^]

Best Wishes,
-David Delaune


这里有两件事...

-只是因为Microsoft说过时不推荐使用某个特定功能并不意味着地球上的其他人都认为是这样.新的C ++标准包含大多数C90标准库,这意味着诸如strcpy之类的功能仍然非常合法.

-话虽如此,为什么在C ++程序中使用诸如strcpy之类的东西?虽然我知道VC ++ 6已经有13年的历史了,但它支持足够的C ++标准库,因此完全无法使用C标准库(有一些令人讨厌的异常,例如重命名文件).

干杯,



PS:出于兴趣,安全功能实际上并没有那么安全-它们使运行时库有机会捕获一些缓冲区溢出,但是我仍然看到(好吧,有5个)程序员的负载跳了起来,而且仍然在使用它们的代码中引入安全漏洞.您最好用C ++编写自己的安全包装器,以自动计算必须提供给所谓的安全"版本的额外尺寸参数.

PPS:对不起,如果这听起来像是一声咆哮,那并不意味着要成为一个,只是一个警告!
Two things here...

- Just ''cause Microsoft say a particular function is deprecated doesn''t mean the rest of the planet thinks it is. The new C++ standard contains most of the C90 standard library which means that functions like strcpy are still very legal.

- Having said that why are you using things like strcpy in a C++ program? While I understand that VC++ 6 is a 13 year old relic it supports enough of the C++ standard library to make it completely pointless to use the C standard library (with a few annoying exceptions, like renaming files).

Cheers,

Ash

PS: Just out of interest the secure functions aren''t actually that much more secure - they give the runtime library the chance to catch some buffer overruns but I''ve still seen loads of (okay, 5) programmers trip up and still introduce security holes into their code while using them. You''d be better writing your own secure wrappers in C++ that automatically calculate the extra size parameters you have to feed to the so called "secure" versions.

PPS: Sorry if this sounds like a rant, it wasn''t meant to be one, just a warning!


这篇关于如何检测使用的编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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