krebstar
krebstar

Reputation: 4056

Microsoft _s functions, are they part of the C++ standard now?

I just recently changed my IDE to MS Visual Studio 2005 coming from MSVC++ 6, and I've gotten a lot of deprecation warnings. Rather than ignore the warning, I started to change them to the _s equivalents. However, I then found out that these were microsoft-only implementations.

I read somewhere that they were pushing for these to become part of the standard. Is it?

Is it a good idea to use these _s functions? Or should I use something else?

Thanks.

Upvotes: 7

Views: 4349

Answers (5)

R.. GitHub STOP HELPING ICE
R.. GitHub STOP HELPING ICE

Reputation: 215487

You should use the standard functions and disable whatever sadistic warnings Microsoft has turned on by default to discourage you from writing standards-conformant code. I seriously doubt the "_s functions" will ever be added to standard C (though they have been proposed) since they are an invention of a single vendor and have never been implemented by any other vendor. (Hey let's incorporate all of POSIX into the C standard while we're at it...)

Upvotes: 1

Michael Burr
Michael Burr

Reputation: 340366

The *_s() functions are not part of the C standard, but there is a pending 'Technical Report' proposing that they be added (I'm not sure if the routines in the TR are exactly the same as Microsoft's or if they're just similar).

TR 24731-1: Extensions to the C Library Part I: Bounds-checking interfaces:

If you want to continue to use the old functions you can keep the deprecation warnings quiet by defining the macro _CRT_SECURE_NO_WARNINGS (was _CRT_SECURE_NO_DEPRECATE which might still be supported).

Upvotes: 13

Dan Olson
Dan Olson

Reputation: 23377

They're being considered for standardization, as far as I'm able to tell. The proposal is TR 24731.

As for whether it's a good idea to use them, I'd say yes. I don't much like the way they catch errors but I believe you can provide them with your own handler. If you need cross-platform compatibility you have two choices: implement them with macros on the non-Windows platforms or turn off the deprecation warnings.

After doing a review through a large codebase I determined that it's nearly impossible to get all programmers to use the C standard library functions for string manipulation correctly, so everything that aims to correct that is a welcome addition.

Upvotes: 1

paxdiablo
paxdiablo

Reputation: 882206

If you're targeting the Microsoft platform, by all means use them. Even if you're not, you can always implement them yourself when (or if) you need to port your software to a non-Microsoft platform.

Worst case is that you end up using a few #ifdefs to conditionally compile.

Upvotes: 1

Suroot
Suroot

Reputation: 4423

You upgraded your IDE and also upgraded your Microsoft libraries. Frankly you can continue to use your old libraries as they continue to be kept (for backwards compatibility) although Microsoft has said that they are going to actually start taking out some of these older functions. I would say that if you're developing forward then you can use the newer functions; if you're developing backwards (or not worrying what the version is) then you might want to use the older functions.

Upvotes: 1

Related Questions