Duke of URL

Consider the following code segment. I have followed the advice of putting the #define CRT_SECURE_NO_DEPRECATE 1 before all #includes, but I'm still getting the warnings:

1>c:\!mtc\src\deprecate_test\deprecate_test.cpp(10) : warning C4996: 'strcpy' was declared deprecated

1> c:\program files\microsoft visual studio 8\vc\include\string.h(73) : see declaration of 'strcpy'

1> Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'

Here's the code:

#define _CRT_SECURE_NO_DEPRECATE 1

#include "stdafx.h"

#include <string.h>

int _tmain(int argc, _TCHAR* argv[])

{

char szBuf[10];

strcpy(szBuf, "test"); // warning: deprecated

return 0;

}



Re: Visual C++ Language _CRT_SECURE_NO_DEPRECATE does not disable warnings

Brian Kramer

You are using precompiled headers. The compiler will scan the cpp file until it finds the #include for the precompiled header (specified with /Fp flag), ignoring all lines before it. (One of those gotchas that I think Microsoft ought to warn on.)

This is a good opportunity to move the #define into stdafx.h so all your subordinate cpp files use it. Alternatively, you can add it to your project settings.

Brian





Re: Visual C++ Language _CRT_SECURE_NO_DEPRECATE does not disable warnings

Jonathan Caves - MSFT

Hi Brian: we just added such a warning :-)




Re: Visual C++ Language _CRT_SECURE_NO_DEPRECATE does not disable warnings

Marius Bancila

Perhaps the best option is to add it to the Project Settings. In that case it will work even if you turn off the precompiled headers.




Re: Visual C++ Language _CRT_SECURE_NO_DEPRECATE does not disable warnings

Brian Kramer

Removing /Yu still results in the #include "stdafx.h" being pulled in.



Re: Visual C++ Language _CRT_SECURE_NO_DEPRECATE does not disable warnings

Andreas Fabri


Note that there is also the macro

_SCL_SECURE_NO_DEPRECATE



andreas