-1

Rule 22 in JSF AV C++ Coding Standards says:

AV Rule 22 (MISRA Rule 124, Revised)

The input/output library <stdio.h> shall not be used.

I understand from this answer why I shouldn't use these functions, but so far I didn't find an answer to what I can do instead? What if I need to print to console or to some other buffer?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
אנונימי
  • 304
  • 2
  • 7
  • 3
    That's a C++ standard — you're expected to be writing C++ code using the `` library instead. You've tagged your question with C — the C++ standards do not apply. The MISRA standards apply to embedded systems (MISRA = Motor Industry Software Reliability Association). If you're working in the industry, then you'll probably have access to I/O libraries that are deemed appropriate (but I'm not sure what they are). If you're not working in the industry, the proscription is probably not really relevant to you. – Jonathan Leffler Jul 18 '22 at 00:21
  • The C++ approach is usually introduced as part of your first "Hello World" program in C++. – paddy Jul 18 '22 at 00:24
  • I'm not sure why, but I'm getting this error on a C file, not C++. so in C++ I can replace printf() with cout, but what can I do in C? – אנונימי Jul 18 '22 at 00:49
  • Consult with those who are imposing the rule on you. We cannot tell the context in which you are working. We cannot tell what alternatives there are for you to use, but alternatives there must be. Neither the MISRA nor the JSF rules will be imposed in a vacuum; there will be documents specifying what's required. If there are no such documents, it's time to leave for somewhere that thinks before imposing rules on developers. (As to why you're getting the error, presumably some checking software is spotting `#include ` and that triggers this rule check/violation.) – Jonathan Leffler Jul 18 '22 at 00:54
  • 1
    In the contexts where MISRA or JSF (Joint Strike Fighter) rules apply, there isn't a console to which you can just write arbitrary messages. When did you last see a message written to the console in your car? In the context where these rules are designed to be used, there aren't things like consoles or standard output. So asking how to output a message to the console is meaningless. But if you're not working on cars or planes, or some similar embedded system, then the rules are probably not relevant. There's a deviation procedure in the MISRA rules for necessary exceptions. – Jonathan Leffler Jul 18 '22 at 01:01
  • 1
    Check with your peers as to how they write debug messages or how they debug their code instead of going it alone. There is probably a "debug only" logging system that can be invoked as required. – cup Jul 18 '22 at 04:32
  • The JSF AV standard, while addressing C++, was written before C++ guidance existed -it was therefore based on MISRA C:1998 (not even MISRA C:2004) @JonathanLeffler – Andrew Jul 19 '22 at 19:07

1 Answers1

0

The JSF AV guidance (which was based on MISRA C:1998) includes similar provision to MISRA's deviation process, allowing violation of a rule if appropriate... this is detailed in AV Rules 4 through 7.

This requires approval from the software engineering lead.

But as Jonathan notes in the comments on the original post, I'm not quite sure where you want to printf() to on an avionics assembly.

If you happen to have a separate debug port/console, then you'll probably need to roll-your-own I/O function anyway.

Andrew
  • 2,046
  • 1
  • 24
  • 37