NEW
Font size
WorksheetsRefresh your basics - MISRA 2012
Total questions: 20
Worksheet time: 22mins
A project with unused type declarations is compliant or not with MISRA?
For example,
int16_t unusedtype ( void )
{
typedef int16_t local_Type;
return 67;
}
Compliant
Non-compliant
The following macro example comes under
void use_macro ( void ) {
#define SIZE 4
#define DATA 3
use_int16 ( SIZE );
}
Assertion: A project containing unused macro declaration will lead to code
redundancy and unclear.
Reason: The unused macro will give an advisory action and leads to un-necessary memory space consumption
The Assertion and the Reason are correct but the Reason is not the correct explanation of the Assertion.
Both the Assertion and the Reason are correct and the Reason is the correct explanation of the Assertion.
Our Assertion is true but the Reason is false.
The statement of the Assertion is false but the Reason is true.
Both the statements are false.
The preprocessor will assume that the macro identifier has a value of zero if
Macro identifier has been defined and not used in preprocessor directive
Macro identifier has not been defined and used in preprocessor directive
Macro identifier has been defined and used in preprocessor directive
Unintentional removal of code occurs if the source line containing a // comment ends with which of the following character?
\
/
*
/*
Which of the following is not compliant with MISRA?
int16_t y[ 3 ][ 2 ] = { 1, 2, 0, 0, 5, 6 };
int16_t y[ 3 ][ 2 ] = { { 1, 2 }, { 0 }, { 5, 6 } };
int16_t y[ 3 ][ 2 ] = { { 1, 2 }, { 0, 0 }, { 5, 6 }
Which of the following is NOT compliant with MISRA?
( bool_t ) false
( int32_t ) 3U
( bool_t ) 3U
( bool_t ) 0
The MISRA Standard only allows which of the below to initialize all elements of an array or struct?
{0u}
{0}
switch ( x == 0 )
{
case false:
y = x;
break;
default:
y = z;
break;
}
Is the above code by using a switch expression with boolean type compliant with MISRA?
Compliant
Non-compliant
uint16_t func ( uin t16_t para1 )
{
return para1;
}
uint16_t x;
void discarded ( uint16_t para2 )
{
func ( para2 ); //Line 1
( void ) func ( para2 ); //Line 2
x = func ( para2 ); //Line 3
}
Which line is not compliant with MISRA?
Line 1
Line 2
Line 3
The result of an assignment operator should not be used.
Which satisfies the above rule?
if ( ( 0u == 0u ) || ( bool_var = true ) )
if ( ( 0u == 0u ) || ( bool_var == true ) )
volatile int32_t i;
int32_t j;
size_t s;
Which of the following is NOT compatible with MISRA?
s = sizeof ( j );
s = sizeof ( j++ );
s = sizeof ( i );
Is it allowed to modify the loop counter in a for loop in the for loop body?
Yes
No
Is it advised to use goto statements for our systems?
Yes
No
All if … else if constructs shall be terminated with an else statement.
True
False
Which is NOT compliant with MISRA?
extern void g ( char c, const k );
extern void g ( char c, const int16_t k );
typedef void ( *pfv ) ( int16_t x );
RULE: A function shall not be declared implicitly.
What kind of MISRA category does this rule fall under?
Mandatory
Advised
Required
What is the meaning of using extern before function declaration? For example following function sum is made extern,
extern int sum(int x, int y, int z)
{
return (x + y + z);
}
Function is made globally available
extern means nothing, sum() is same without extern keyword
Function need not to be declared before its use
Function is made local to the file
In C, parameters are always by default
Passed by value
Passed by reference
Non-pointer variables are passed by value and pointers are passed by reference
Passed by value result
According to MISRA C coding standards, is the following declaration correct?
static foo(void);
False
True
Pick the correct statement for const and volatile.
const is the opposite of volatile and vice versa.
const and volatile can’t be used for struct and union.
const and volatile can’t be used for enum.
const and volatile can’t be used for typedef.
const and volatile are independent i.e. it’s possible that a variable is defined as both const and volatile.
