468,463 Members | 2,121 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,463 developers. It's quick & easy.

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)

Oct 17 '06 #1
11 17320

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
}

Oct 17 '06 #2

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 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)

Oct 17 '06 #3
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) ?
There is no strncpy_s in the current standard. I also didn't find it in the
TR1 draft.
2) gcc 4.1.1 does not seem to have strncpy_s - is that correct
(Or do I miss an include or something)
The gcc mailing lists would be a good place for this question.
Best

Kai-Uwe Bux
Oct 17 '06 #4
On 17 Oct 2006 01:25:32 -0700, "tmartsum" <tm******@gmail.comwrote:
>I have been doing some (re)search on the VS-warning
warning C4996: 'strncpy' was declared deprecated
Those functions shall make the notoriously error-prone C string
functions a little safer.
>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) ?
IIRC, there are ongoing activities to standardize those functions.
>2) gcc 4.1.1 does not seem to have strncpy_s - is that correct
(Or do I miss an include or something)
Maybe you'll find a free implementation?

Best wishes,
Roland Pibinger
Oct 17 '06 #5

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.
Right. It isn't deprecated by C or C++. But since this is clc++, I'll
ignore ISO C.
However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?
I think it was (part of) a proposal at some time, for the C++0x
release. It's
not in TR1, though.
2) gcc 4.1.1 does not seem to have strncpy_s - is that correct
Correct, but really off-topic here. ISO C++ doesn't have strncpy_s.

The level of verbosity typically depends on the exact compiler
settings. ISO
allows any warning, as long as legal C++ code still works. This
particular
warning can be turned off just with a setting, too. This would be the
best
approach if you desire portable code.

HTH,
Michiel Salters

Oct 17 '06 #6

Mi*************@tomtom.com 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.

Right. It isn't deprecated by C or C++. But since this is clc++, I'll
ignore ISO C.
However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?

I think it was (part of) a proposal at some time, for the C++0x
release. It's
not in TR1, though.
2) gcc 4.1.1 does not seem to have strncpy_s - is that correct

Correct, but really off-topic here. ISO C++ doesn't have strncpy_s.

The level of verbosity typically depends on the exact compiler
settings. ISO
allows any warning, as long as legal C++ code still works. This
particular
warning can be turned off just with a setting, too. This would be the
best
approach if you desire portable code.

HTH,
Michiel Salters
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++...

Oct 17 '06 #7
"tmartsum" <tm******@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
>
Mi*************@tomtom.com 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.

Right. It isn't deprecated by C or C++. But since this is clc++, I'll
ignore ISO C.
However MS wants this to be replaced with strncpy_s
1) Is it c++,TR1 or just MS standard (TR proposal) ?

I think it was (part of) a proposal at some time, for the C++0x
release. It's
not in TR1, though.
2) gcc 4.1.1 does not seem to have strncpy_s - is that correct

Correct, but really off-topic here. ISO C++ doesn't have strncpy_s.

The level of verbosity typically depends on the exact compiler
settings. ISO
allows any warning, as long as legal C++ code still works. This
particular
warning can be turned off just with a setting, too. This would be the
best
approach if you desire portable code.

HTH,
Michiel Salters

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.
Oct 17 '06 #8
Salt_Peter wrote:
Frankly, no-one cares what MS thinks.
Well, the chair of the ISO C++ commitee is from Microsoft, and there's
only like eleventy billion lines of code written for MS platforms.
Perhaps MS does have something to say after all.

Regards,
Bart.

Oct 17 '06 #9

tmartsum wrote:
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/WG...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/WG...docs/n1146.pdf

Greg

Oct 18 '06 #10

Jim Langston wrote:
"tmartsum" <tm******@gmail.comwrote 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

Oct 18 '06 #11

tmartsum wrote:
Mi*************@tomtom.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>
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

Oct 18 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

45 posts views Thread by Matt Parkins | last post: by
68 posts views Thread by Roman Ziak | last post: by
62 posts views Thread by Juuso Hukkanen | last post: by
7 posts views Thread by jacob navia | last post: by
7 posts views Thread by AlanJSmith | last post: by
70 posts views Thread by junky_fellow | last post: by
reply views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.