 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
tmartsum Guest
|
Posted: Tue Oct 17, 2006 9:10 am Post subject: strncpy_s and gcc ? |
|
|
I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated
It seems to be a MS-way to force strncpy to become deprecated, but it
is not ISO-deprecated.
However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?
2) gcc 4.1.1 does not seem to have strncpy_s - is that correct
(Or do I miss an include or something) |
|
| Back to top |
|
 |
Salt_Peter Guest
|
Posted: Tue Oct 17, 2006 9:10 am Post subject: Re: strncpy_s and gcc ? |
|
|
tmartsum wrote:
| Quote: | I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated
It seems to be a MS-way to force strncpy to become deprecated, but it
is not ISO-deprecated.
However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?
2) gcc 4.1.1 does not seem to have strncpy_s - is that correct
(Or do I miss an include or something)
|
Frankly, no-one cares what MS thinks. Copying an object, like a string,
should be handled by a copy constructor, period. When you hear MS say
the word "string", that can mean a lot of different things.
#include <string>
int main()
{
std::string s("a short string");
std::string copy(s); // and that's how you copy a string - copy ctor
- simplicity defined
} |
|
| Back to top |
|
 |
tmartsum Guest
|
Posted: Tue Oct 17, 2006 9:10 am Post subject: Re: strncpy_s and gcc ? |
|
|
Salt_Peter skrev:
| Quote: | tmartsum wrote:
I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated
It seems to be a MS-way to force strncpy to become deprecated, but it
is not ISO-deprecated.
However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?
2) gcc 4.1.1 does not seem to have strncpy_s - is that correct
(Or do I miss an include or something)
Frankly, no-one cares what MS thinks. Copying an object, like a string,
should be handled by a copy constructor, period. When you hear MS say
the word "string", that can mean a lot of different things.
#include <string
int main()
{
std::string s("a short string");
std::string copy(s); // and that's how you copy a string - copy ctor
- simplicity defined
}
|
You are right - this is the way it should be, but unfortunately it does
not answer my question on status on strncpy_s.
The situation is that I have a lot of old code with old char*-strings.
Now when I compile VS says something and gcc says something else.
What is the truth about it ?
So the question remains ....
(But thanks for your input) |
|
| Back to top |
|
 |
Gavin Deane Guest
|
Posted: Wed Oct 18, 2006 9:10 am Post subject: Re: strncpy_s and gcc ? |
|
|
tmartsum wrote:
| Quote: | Michiel.Salters (AT) tomtom (DOT) com skrev:
tmartsum wrote:
I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated
|
<snip discussion of strncpy vs strncpy_s>
| Quote: | ISO allows any warning, as long as legal C++ code still works.
OK - so MS is allowed to give any warning - I am however not happy with
warnings that suggest me to change my code into something that is not
(ISO) c++...
|
Depending on your level of unhappiness, you have several options. For
example, you could do one or more of the following:
Contact Microsoft and give them your feedback as a customer.
Vote with your feet and change to a different compiler vendor.
Look in Microsoft's documentation for the way to switch off that
warning now you understand why it's there and why you don't want it.
The last one has worked for me.
Gavin Deane |
|
| Back to top |
|
 |
Greg Guest
|
Posted: Wed Oct 18, 2006 9:10 am Post subject: Re: strncpy_s and gcc ? |
|
|
Jim Langston wrote:
| Quote: | "tmartsum" <tmartsum (AT) gmail (DOT) com> wrote in message
ISO allows any warning, as long as legal C++ code still works.
OK - so MS is allowed to give any warning - I am however not happy with
warnings that suggest me to change my code into something that is not
(ISO) c++...
That's Microsoft for you. And it should be _strncpy_s since it's an
extension. Microsoft did that from some calls from VC6 to VC .net 2003,
but on this one I think they thought it would be in the new standard or
something.
|
Not necessarily. Whether strncpy_s is defined or not could be made
dependent on the definition of an implementation-reserved identifier.
Since no conforming program would have already defined this identifier,
there is no chance that the these extensions would break a conforming
program. Instead, a C or C++ program has to first define
__STDC_WANT_LIB_EXT1__ before it can call any of the routines in the TR
"bounds-checked" extension to the standard C library.
Greg |
|
| Back to top |
|
 |
Greg Guest
|
Posted: Wed Oct 18, 2006 9:10 am Post subject: Re: strncpy_s and gcc ? |
|
|
tmartsum wrote:
| Quote: | Salt_Peter skrev:
tmartsum wrote:
I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated
It seems to be a MS-way to force strncpy to become deprecated, but it
is not ISO-deprecated.
However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?
2) gcc 4.1.1 does not seem to have strncpy_s - is that correct
(Or do I miss an include or something)
Frankly, no-one cares what MS thinks. Copying an object, like a string,
should be handled by a copy constructor, period. When you hear MS say
the word "string", that can mean a lot of different things.
#include <string
int main()
{
std::string s("a short string");
std::string copy(s); // and that's how you copy a string - copy ctor
- simplicity defined
}
You are right - this is the way it should be, but unfortunately it does
not answer my question on status on strncpy_s.
|
The routine strncpy_s() and the other, related "_s"-suffixed Standard C
library routines are an ISO - and not a Microsoft - set of extensions.
Specifically the "bounds-checking" interfaces are a draft TR extension
to the standard C library. They will no doubt will eventually make
their way into the C and C++ Standards.
Nor would I recommend waiting before adopting bounds-checking routines
to replace their unsafe C library equivalents. After all, blind
adherernce to "standards" is no excuse for writing insecure programs.
For futher reading:
Status of various C Standard projects:
http://www.open-std.org/JTC1/SC22/WG14/www/projects#24731
which includes a link to the latest Draft of the the bounds-checking C
Library extensions:
http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1146.pdf
Greg |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|