MSDN clearly states that if you define _CRT_SECURE_NO_DEPRECATE it "will disable deprecation warnings".
I tried adding _CRT_SECURE_NO_DEPRECATE to the Preprocessor Definitions and #define _CRT_SECURE_NO_DEPRECATE to the code. In both cases I still get a C4996 warning from every single strcpy call. The only way to disable the warning, as far as I can tell, is to use #pragma warning (disable:4996) or add the warning to the C/C++ settings (Advanced > Disable Specific Warnings). But this will disable all deprecated warnings and I only want to disable insecure CRT warnings (str... functions).
Is the MSDN documentation false or am I doing something wrong

_CRT_SECURE_NO_DEPRECATE has no effect
Chris Moughan
You must declare _CRT_SECURE_NO_DEPRECATE before including any CRT files (like stdio.h or string.h) in order to disable the deprecation warnings. For instance:
#include <stdio.h>
#include <string.h>
#define _CRT_SECURE_NO_DEPRECATE
int main()
{
printf("hello\n");
char buf[30], buf2[30];
buf2[0] = 'h';
buf2[1] = 0;
strcpy (buf,buf2);
}
Will give you a deprecation warning while:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <string.h>
int main()
{
printf("hello\n");
char buf[30], buf2[30];
buf2[0] = 'h';
buf2[1] = 0;
strcpy (buf,buf2);
}
Will not. The easiest way to do this is simply to throw /D_CRT_SECURE_NO_DEPRECATE onto the command line for compilation. (after cl.exe if you're compiling on the command line or in the project settings if your using the ide).
Ben Anderson,
VC++ Team
qrt999
The Preprocessor Definition I have are:
_CRT_SECURE_NO_DEPRECATE
_DEBUG
WIN32
_WINDOWS
_AFXEXT
WINVER=0x0500
Gaj?tko
P R W
I can send a sample project, but the smallest one I can come up with right now is 10MB (zipped). I could strip the project a little but I'm a little pressed for time at the moment. Do you still want it
THE RAZI
Yep, that works. For some reason adding the two defines in the Preprocessor Definitions doesn't work. Adding them to Stdafx.h does. Also, MSDN has no mention of _CRT_NONSTDC_NO_DEPRECATE, so I think it's safe to say that MSDN docs are faulty on this matter.
Anyways, problem solved. Thanks very much for your help, Martin.
FrdBed
Thanks,
Mo
Anpiro
I am sorry that I didn't asked for the detailed warnings you got.
Define _CRT_NONSTDC_NO_DEPRECATE too!
Your code compiles in the Debug build with 1 warning and this warning is absolutely correct. There are link errors but I think they occur because I didn't
I would recommend that you set those defines in your stdafx.h! Nobody looks into the project settings but the stdafx.h is a good place to document this!
PS: I will delete your files if you mark this comment as "Answer to your question".
werd123
Andr&#233; Alves
SMILEMan
Adding the definitions to the Preprocessor works but adding them on top of Stdafx.h, before any #include still doesn't.
I am trying to make keep my projects backward compatible with VS 6.0, that is why I don't want to update my .dsp file. The following is on the top of Stdafx.h. It works well for one MFC GUI project, but not for a Win32 Dll:
#if _MSC_VER > 1200
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE
#if defined(_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
#undef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#else
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#endif
#endif
Mo
idoOv
Please only use a ZIP file.
mjt
I just hit the exact situation as above in which adding:
to the command line did not solve the problem. The reason for me turned out to be that I needed to recompile my precompiled header to ensure that it was using the new defines.
Normally I'd have thought that the compiler would have complained that I was using an out of date precompiled header, but it didn't in this case. Seems like a bug to me.
boisebiker
Thanks,
Ayman Shoukry
VC++ Team
porov
Any how: to your question about: _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES
I have nothing else than this link.
http://msdn2.microsoft.com/en-us/library/ms175759