"warning C4996: 'strncpy' was declared deprecated"

  • Thread starter Thread starter Olaf Baeyens
  • Start date Start date
O

Olaf Baeyens

I am testing VC++ 2005 and I get this warning:
"warning C4996: 'strncpy' was declared deprecated"

Does that mean that they might be phased out in VC++ 2006 or higher?
Or does an alternative function exist as replacement?
 
Yes, you should use strncpy_s. See "Security Enhancements in the CRT" on
MSDN.
 
Hi Olaf!
I am testing VC++ 2005 and I get this warning:
"warning C4996: 'strncpy' was declared deprecated"
Does that mean that they might be phased out in VC++ 2006 or higher?
Yes.

Or does an alternative function exist as replacement?

See: strncpy_s
http://msdn2.microsoft.com/library/5dae5d43(en-us,vs.80).aspx

Almost for every deprecated CRT function there is a "xxx_s" function
available (only for strdup, there is only a _strdup).

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Olaf said:
I am testing VC++ 2005 and I get this warning:
"warning C4996: 'strncpy' was declared deprecated"

Does that mean that they might be phased out in VC++ 2006 or higher?

Not likely, since strncpy is an ISO C and C++ function, and is more
efficient than strncpy_s. The deprecation warning is not intended to
indicate that the standard functions will be removed, but rather to
indicate potentially unsafe code. In fact, the _s functions are of
dubious use in any case, since they don't make it significantly easier
to write correct code in many cases (though they do make it easier to
improve legacy code). There is a #define to get rid of the warnings, I
forget what it is though.
Or does an alternative function exist as replacement?

strncpy_s, but that is non-standard and non-portable for the time being
(but there is a controversial C standard technical report under discussion).

Tom
 
Hi Tom!
There is a #define to get rid of the warnings, I
forget what it is though.

The following defines can be used to get rid of the warnings:
- _CRT_SECURE_NO_DEPRECATE
- _CRT_­NONSTDC_NO_DEPRECATE
- _USE_32BI­T_TIME_T
strncpy_s, but that is non-standard and non-portable for the time being
(but there is a controversial C standard technical report under
discussion).

The standard can be found here:
http://www.opengroup.org/platform/single_unix_specification/uploads/40/6355/n1093.pdf

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Hi Tom!
I think it's worth making it clear that it isn't a standard, but rather
a draft technical report, and one that may never become a real technical
report, and will almost certainly never become part of the full C or C++
standards.

There are a lot of misleading discussions in this area.
And I will not add my comment here... (in any case, it will be
interpreted the wrong way).

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Back
Top