You are on page 1of 3

Exp No: 03 APPLYING MISRA C STANDARDS FOR WRITING C

PROGRAMMING
Date:

Aim:
To write efficient C code by adapting MISRA and CERT coding standards.
Software Requirement:
 Ubuntu Linux distros

 Text editors like gedit, VI in linux with gcc

Procedure:
 Develop a C program and execute using gedit in gcc compiler
 Compile the developed C program in the terminal window using gcc compiler
 Implement the MISRA C conding standard in the developed C program
 Compile and Execute the MISRA C coding standard implemented C program
using gcc compiler
 Compare the results using terminal window.

Commands:
 For installing GCC:
 sudo apt-get update
 sudo apt-get install build-essential manpages-dev
 To write programs:
Install gedit text editor
 sudo apt-get install gedit
To open text editor
 gedit myfirstprog.c
It will create and open a file named myfirstprog.c, type the C program in text
editor.
 To compile and Run:
 $ gcc –o myfirstprog myfirstprog.c
 ./myfirstprog
Required Rules:- 122 Required Rules – must follow the rules - mandatory

Advisory Rules:- 20 Rules – do not have the mandatory status

Programs based on MISRA Rules:


Rule 9.1(required) - All automatic variables shall have been assigned a value before
being used. (MISRA C: 2004)

Non Compliance code Compliance Code

#include<stdio.h> #include<stdio.h>
void main() void main()
{ {
int a; int a=50,
printf(“Hello!\n”); printf(“Hello!\n”);
printf(“Enter Reg. NO:\n”); printf(“Enter Reg. No.\n”);
scanf(“%d”,&a); scanf(“%d”,&a);
printf(“Your Reg. No. Is:%d”,a); printf(“Your Reg. No. Is:%d”,a);
} }

Rule 8.2(required) – Whenever an object or function is declared, its type shall be


explicitly updated. (MISRA C: 2004).

Non Compliance code Compliance Code

#include<stdio.h> #include<stdio.h>
void main() void main()
{ {
const a=50; const int a=50;
printf(“integer constant:%d”,a); printf(“integer constant:%d”,a);
return 0; return 0;
} }
Rule 9.1: Output

Rule 8.2: Output

Result:
Thus the C program for MISRA C standard and CERT C standard is developed
and executed in Ubunto Desktop Distros using gcc compiler.

You might also like