0

Using the function strcpy in MS Visual Studio gives me an error saying I should use strcpy_s which is safer to use. Is strcpy_s part of the C++ standard? Or is it only part of Microsoft Visual C++?

Will code containing strcpy_s only compile in Visual Studio?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Jorge Luque
  • 435
  • 1
  • 4
  • 17

1 Answers1

2

strcpy_s() is an optional part of C11 (more formally called a "conditional feature". Implementations are permitted to not implement the "Bounds-checking interfaces" standardized in Annex K.

Some other conditional features of C11 include:

  • atomics
  • complex types
  • threads
  • variable length arrays (the interesting this about this is that VLAs were not optional in C99)
Michael Burr
  • 333,147
  • 50
  • 533
  • 760
  • I see. I have only learned C++ and not C, do most things in the C standard also apply to C++? If so, does that mean that many C++ features are not mentioned in the C++ standard because they were already described in the C standard? – Jorge Luque Apr 08 '16 at 06:14
  • 1
    C++11 and C++14 refer to the C99 standard. As far as I know this is still the case in the most recent draft of what's supposed to be C++17. I don't know if there are plans to update C++17 to refer to C11 or not. But even if they do the bounds-checking interfaces would presumably still be optional. As far as I know, the glibc developers are not inclined to implement Annex K. Ulrich Drepper has posted quite negatively about it in the past. – Michael Burr Apr 08 '16 at 15:31