how to resolve MISRA 10.3 violation?

조회 수: 8 (최근 30일)
snehal pawar
snehal pawar 2019년 9월 3일
답변: Anavi Somani 2023년 7월 10일
In my C project I have use
typedef unsigned char uint8;
uint8 arry[10];
arry[5] = 'E';
but i got an MISRA violation 10.3 as "The expression is assigned to an object with a different essential type category" how to resolve this violation
thanks in advance
  댓글 수: 1
David Sosa
David Sosa 2022년 8월 4일
A "char" and a "uint8_t" have different essential type categories (see The MISRA Essential type model).
To solve your issue you need to have a "char arr[10]". Then the violation will go away.

댓글을 달려면 로그인하십시오.

답변 (1개)

Anavi Somani
Anavi Somani 2023년 7월 10일
You are giving an object of type uint8, an unsigned integer type, the value of the letter "E," which is a MISRA violation. According to MISRA C:2012 Rule 10.3, the assignment is not permitted since the character "E" belongs to a different essential type category than an unsigned integer.
There are a few options for dealing with this violation.
  • One approach is to convert the object's type to a character type. To achieve this, declare the object as char rather than uint8.
  • Use a cast to explicitly convert the value of the character to an unsigned integer.
typedef unsigned char uint8;
uint8 arry[10];
arry[5] = (uint8)'E';

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by