<cstdio> explicitly banned but not <fstream> or <ostream>

Moderators: david ward, misra cpp

Post Reply
Posts: 1
Joined: Wed Jul 07, 2010 11:51 am
Company: Lockheed Martin INSYS UK

<cstdio> explicitly banned but not <fstream> or <ostream>

Post by KCCMITCELL » Wed Jul 07, 2010 3:17 pm

Rule 27-0-1 specifically bans the use of library <cstdio> for access to the external file system but not <fstream>. Do we imply from this that <fstream> is a safer alternative, or is it considered inherently unsafe, in any case, for application code to access the file system at run-time.

This question is asked in the context that the real-time software for our vehicle-based military project may be required to read configuration parameters from file at start-up, and log telemetry data during run-time.

It is also noted that std::cout (<ostream>) is used in the example code for Rule 3.4.1., whereas printf would be banned under Rule 27-0-1.

Posts: 2
Joined: Thu Jan 13, 2011 7:31 am
Company: SAAB

Re: <cstdio> explicitly banned but not <fstream> or <ostream

Post by sthrjo » Fri Jan 21, 2011 2:02 pm

As I understand <iostream> may be used as long as dynamic heap memory allocation is avoided (18-4-1), and the library is reliable, see "3.5 Library Issues".

misra cpp
Posts: 163
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: <cstdio> explicitly banned but not <fstream> or <ostream>

Post by misra cpp » Tue Oct 11, 2016 11:18 am

We agree with the post of sthrjo Fri Jan 21, 2011
Posted by and on behalf of
the MISRA C++ Working Group

Post Reply

Return to “6.27 Input/output library (C++)”