This is not a duplicate as you might think in first look.
The strcpy()
deprecation in Visual Studio is already known for a few years, as a difficulty when you try to port your C code from GCC to MSVC.
In Visual Studio 2013, all the workarounds of defining _CRT_SECURE_NO_WARNINGS
fail to solve the issue - the compilation is still failing on this error (It is called "warning", but it is actually an error that causes the compilation to fail).
My question is whether there is an elegant way to solve it within the code?
For example, such a macro would help me a lot:
#ifdef SOMETHING_THAT_INDICATES_ITS_MSVC_COMPILER
Some macro that makes the following substitution:
strcpy(dest, src) -> strcpy_s(dest, strlen(src), src)
#endif
Could you please tell me:
- If you think it is a good approach to solve this portability issue?
- How to correctly write such a macro?
- Any other recommendations?