Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





  Rule 8.8 clarification
Posted by: anuj1085 - 10-02-2015, 10:41 AM - Forum: 8.8 Declarations and defnitions - Replies (1)

Just wanted to clarify the rule, i understand this is non-compliance:
==========================================================
static void xyz();
void xyz() /*Non_compliant */
{
...........
}
==========================================================

But the i have query regarding the following:
==========================================================
void xyz();
static void xyz() /* Is this non-compliance*/
{
...............
}
==========================================================
So in the above case where first the function is declared as extern(by default), would it be non complaint under this rule to define it static?

Print this item

  Regd-Rule 12.6 and 12.7
Posted by: Nasi - 23-01-2015, 03:54 AM - Forum: MISRA AC AGC discussions - Replies (1)

The following code is Auto generated code from Embedded Coder of Matlab Simulink.

Code:
tmp = Common_Signal_Process_DWork.UnitDelay_DSTATE_b[1] * ((int16_T)(16384 -
      Common_Signal_Process_DWork.UnitDelay3_DSTATE_d));

    /* Switch: '/Thrs~=4' incorporates:
     *  Product: '/Product1'
     *  Switch: '/Thrs~=3'
     */
    rtb_Thrs5_idx_1 = (int16_T)((tmp >> 14) + ((tmp & 8192) != 0));
    rtb_Thrs5_idx_2 = Common_Signal_Process_DWork.UnitDelay_DSTATE_b[2];
    rtb_Thrs5_idx_3 = Common_Signal_Process_DWork.UnitDelay_DSTATE_b[3];
  }


rtb_Thrs5_idx_1 = (int16_T)((tmp >> 14) + ((tmp & 8192) != 0));
On the Highlighted code above, we are getting MISRA-C 12.6 and 12.7 Rule violations. How to remove this violation?

Print this item

  Subsets of MISRA-C 2004 rules, and quality objectives
Posted by: reito - 30-12-2014, 03:18 PM - Forum: General Questions - Replies (1)

Dear colleagues,
I have received a paper where the authors talk about three different "subsets of MISRA-C 2004 rules". Each subset is related to a different "quality objective", that are in turn related to the SW criticality.
I have checked the MISRA-C 2004 document and I think that it does not contain any reference to these "rule subsets", with the exception of the advisory or required character and the classification of the rules by type.

I would like to know if this practice (having "rules subsets") is common in the automotive industry, and whether there is a shared reference to make this categorization of the rules subsets depending on the SW criticality.

Thanks in advance,

Ricardo

Print this item

  MISRA Rules Ambiguity
Posted by: igor.gvero - 23-12-2014, 08:59 PM - Forum: C++ General - Replies (1)

My name is Igor Gvero and I am a Product Manager/Owner at Klocwork. Our developers had few questions with respect to ambiguity of some rules. Questions are below.
NOTE: THESE ARE NOT SECTION 6 INQUIRIES - SO I AM POSTING THE QUESTIONS HERE

1. Concerning the Rule 5-0-15 of the MISRA C++ 2008 standard, is the following example compliant with the rule?

struct Bar
{
int32_t* dataP[2];
};

void f()
{
int32_t myarray[10];
Bar b;
b.dataP[0] = myarray;
b.dataP[1] = myarray;

int32_t c = (b.dataP[1])[3]; // Is this expression compliant with the rule 5-0-15?
}

The reason that I am asking this question is that the examples for the rule 5-0-15 seem to be contradictory about the use of pointers as arrays. For example, the following are examples from the documentation of the rule 5-0-15:

void my_fn(uint8_t * p1, uint8_t * p2[ ])
{
...
p1[ 5 ] = 0; // Non-compliant – p1 was not declared as array
...
}

uint8_t a[ 10 ];
uint8_t * p;
p = a;
p[ 5 ] = 0; // Compliant : seems to be contradictory with the previous example where it is non-compliant.

I would appreciate if you could explain the exact rule for the use of pointers as arrays in your answer.


2. Concerning the Rule 2-10-2 of the MISRA C++ 2008 standard, is operator overloading allowed for this rule? I think it should be allowed, but I would like to be sure. The rule discuss about identifiers. An operator name should not be an identifier, thus operator overloading should be allowed, but it is not clear from the rule. For example, is the following example compliant with the rule?

#include
#include

namespace myNamespace {
class myClass {
public:
static void* operator new(size_t); // Is this operator overloading compliant with rule 2-10-2?
};
}


3. Concerning the Rule 5-0-2 of the MISRA C++ 2008 standard, can one use parentheses for the operand of the sizeof operator? The rule states that “Parentheses are not required for the operand of a unary operator”. Sizeof is unary operator, thus parentheses should not be required. However, it is common practice to use parentheses with this operator (and even some MISRA examples use this style like rule 5-3-4). Here are some examples to help understand my question:

uint8_t* a = ...;

sizeof *a; // Should be compliant with the rule.
sizeof (int); // Should be compliant with the rule too since the operand is a cast.

sizeof(*a); // This is the one that I am not sure of. I think that it should be accepted but the rule seems to say otherwise.

Print this item

  Problem with MISRA C 2012 Rule 13.5
Posted by: jbrookley - 18-12-2014, 05:55 PM - Forum: 8.13 Side effects - Replies (4)

I am using Parasoft's C++ test and I'm getting a line flagged. The code is as follows:

Code:
if((padcValue1 = 4902)||(padcValue2 = 4902))  /* Error on this line here */
{
    LogFailure(FlagStartupDACTest);
    StartupFail = 1;
}

The error says "Do not use expressions with side effects in the right-hand operand of a logical operator". Is it saying I can't use multiple or cases or is the concern about making it coded so it's easier to test for MC/DC? I can break it up further but it just seems like an inefficient way to code it (unless there's an added benefit or I'm missing the intent of the code).

Any help you can give me would be greatly appreciated! Thanks!

Print this item

  "declaration" in other rules
Posted by: satoshi - 11-12-2014, 04:48 AM - Forum: 8.8 Declarations and defnitions - Replies (1)

Hello

Please teach me the definition of "Declaration" in MISRA-C:2012.

We have read the amplification of rule 8.5.
A member say, "MISRA-C declaration does not include definition, always."
And another member say, "normally, MISRA-C declaration is same as standard-C (include definition)."

We understand that the "Declaration" in Rule 8.5 does not contain "Definition".
In basically, does "Declaration" include "Definition" ?

Best Regards,
Satoshi Kawajiri

Print this item

  Essential Type of preprocessing statement
Posted by: misra-c - 05-12-2014, 01:47 PM - Forum: 8.10 The essential type model - Replies (1)

Does the essential type system intended to apply to preprocessing expressions?
For example:

Code:
void foo (void)
{
   (0 == 1) + 1;        /* non-compliant with Rule 10.1 */
}

#if (0 == 1) + 1     /* compliant or non-compliant with Rule 10.1 ? */

#endif

Print this item

  Clarification of Composite Expressions and casts
Posted by: rgamble - 03-12-2014, 02:45 PM - Forum: 8.10 The essential type model - Replies (1)

In the example below, is the cast to uint32 in the statement in which r2 is assigned a violation of Rule 10.8?

Code:
typedef unsigned short uint16;
typedef unsigned int uint32;

void func(uint16 a, uint16 b) {
    uint32 r1;
    uint32 r2;
    r1 = (uint32) (a - b); // Violation of 10.8
    r2 = (uint32) (uint16) (a - b); // Violation of 10.8?
}

There do not seem to be any examples that specifically comment on this case but the wording of the definition of 'composite expression' introduces room for uncertainty. In particular, the part that says a composite expression
is the 'direct result of a composite operator'. What is the significance of 'direct' in the definition? Does (a - b) lose it's status as a composite expression after being cast to uint16 due to no longer being a 'direct result' of the composite operator? Or does 'direct' refer to something else? Finally, if this example is a violation of 10.8, is there a suggested means to avoid a violation without introducing a temporary variable?

Print this item

  Essential type of wchar_t?
Posted by: sca2012 - 21-11-2014, 03:18 PM - Forum: 8.10 The essential type model - Replies (1)

What is the essential category and rank of (implementation dependent) C99 type wchar_t?

Print this item

  size_t and Rule 3-9-2
Posted by: markturney - 21-11-2014, 02:34 PM - Forum: 6.3 Basic concepts (C++) - Replies (1)

Hello,

Rule 3-9-2 states that "typedefs that indicate size and signedness should be used in place of the basic numerical types."

It specifically states that "The basic numerical types of char, int, short, long, float, double and long double should not be used, but specific-length typedefs should be used."

What about size_t? The signedness is known, but the specific-length is not.

Does this code snippet violate 3-9-2?

Code:
std::vector collection(3, 5);

for (std::size_t ii = 0, count = collection.size(); ii < count; ++ii)
{
    processElement(collection[ii]);
}

Thank you for the help,
Mark

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,309
» Latest member: 1fuhd
» Forum threads: 1,066
» Forum posts: 2,933

Full Statistics

Online Users
There are currently 92 online users.
» 0 Member(s) | 88 Guest(s)
Bing, Facebook, Google, UptimeRobot

Latest Threads
13.2 Was TC2 correctly ap...
Forum: 8.13 Side effects
Last Post: misra-c
08-10-2026, 12:47 PM
» Replies: 1
» Views: 625
20.12 Does the stringific...
Forum: 8.20 Preprocessing directives
Last Post: misra-c
08-10-2026, 12:40 PM
» Replies: 1
» Views: 555
13.3 Should side effects ...
Forum: 8.13 Side effects
Last Post: misra-c
08-10-2026, 12:37 PM
» Replies: 1
» Views: 428
11.6 pointer to pointer t...
Forum: 8.11 Pointer type conversions
Last Post: misra-c
08-10-2026, 12:21 PM
» Replies: 2
» Views: 1,032
What is the UTLR of -1?
Forum: 8.10 The essential type model
Last Post: misra-c
08-10-2026, 12:15 PM
» Replies: 1
» Views: 598
10.3 Clarify if narrower ...
Forum: 8.10 The essential type model
Last Post: misra-c
08-10-2026, 11:57 AM
» Replies: 1
» Views: 508
It 8.12 intended to be so...
Forum: 8.8 Declarations and defnitions
Last Post: misra-c
08-10-2026, 11:50 AM
» Replies: 1
» Views: 455
Rule 0.1.1 Example f4
Forum: 4.0 Language independent issues
Last Post: cgpzs
07-10-2026, 11:07 AM
» Replies: 3
» Views: 728
Rule 6-2-2 Usage of std::...
Forum: 6.6 Statements (C++)
Last Post: misra cpp
25-09-2026, 05:43 PM
» Replies: 1
» Views: 437
M5-0-4 switch over unscop...
Forum: 6.5 Expressions (C++)
Last Post: misra cpp
25-09-2026, 01:00 PM
» Replies: 3
» Views: 541