17.2 The C standard library

17.2.1 Wrap use of the C Standard Library

The C11 standard library, which is included in the C++ standard library, leaves the handling of concerns relating to security and concurrency up to the developer. Therefore, if the C standard library is to be used, it should be wrapped, with the wrappers ensuring that undefined behavior and data races will not occur.

#include <cstdio>
#include <cerrno>
               
bool foo ()
{
std::puts ("hello world"); // @@- Non-Compliant -@@
return (0 == errno);       // @@- Non-Compliant -@@
}

The wrapper code should be placed in separate source files, and this rule should be deviated for those files only.

References

  • JSF AV C++ Rev C – 17
  • MISRA C++:2008 – 19-3-1

Click here for references