Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to printf() for MISRA C : 2004 compliant code

Tags:

c

stdio

misra

I am new to coding using MISRA C guidelines.

The following are two rules in MISRA C 2004:

Rule 16.1 (required): Functions shall not be defined with a variable number of arguments. Rule 20.9 (required): The input/output library <stdio.h> shall not be used in production code.

This clearly means that I can't use printf in production code for it to be MISRA C compliant, because printf is a part of <stdio.h> and allows a variable number of arguments. So I set out on a quest to find out how I can write my own printf statement. So far I am unable to find any solution for this predicament. Any help from fellow developers would be appreciated.

like image 735
Wait What Avatar asked Sep 14 '25 01:09

Wait What


1 Answers

so far I am unable to find any solution for this predicament

You have to use functions that print one (countable) things at a time. An example interface you might want to implement might look like the following:

print_string("Hello");
print_int(5);
print_char('\n');
like image 123
KamilCuk Avatar answered Sep 16 '25 17:09

KamilCuk