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

Username
  

Password
  





  Rule 8.8 Does this apply to after pre-processing
Posted by: misra-c - 13-02-2015, 09:56 AM - Forum: 8.8 Declarations and defnitions - Replies (1)

Is the following code compliant with rule 8.9 “An object should not be defined at block scope if its identifier only appears in a single function”?

Code:
#define MACHINE1 0
int32_t x;   /* compliant or not? */

void fn1 ( void )
{
   x = 3;
}

int32_t fn2 ( void )
{
#if ( MACHINE1 )
   return x;
#else
   return 0;
#endif
}

Print this item

  Dir 4.8 2 struct pointers in a Translation unit
Posted by: misra-c - 13-02-2015, 09:46 AM - Forum: 7.4 Code design - Replies (1)

What happens if there are 2 pointers to a struct/union in a translation unit. One which accesses the details of the struct/union and the other does not. For Example:
File1.h

Code:
struct X { int32_t i1 };
  typedef struct X * ptrX;
  extern  void use_ptrX ( ptrX p );

File1.c
Code:
void fn ( ptrX a, ptrX b )
  {     /* no reference to a->i1 in translation unit  - does the type of "a" need to be opaque? */
     use_ptrX ( a );
     use_int32 ( b -> i1 ) ;
}

Print this item

  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

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,171
» Latest member: stephanmuench
» Forum threads: 998
» Forum posts: 2,752

Full Statistics

Online Users
There are currently 340 online users.
» 0 Member(s) | 338 Guest(s)
Bing, Google

Latest Threads
Rule 6.2.1: non-inline co...
Forum: 4.6 Basic concepts
Last Post: cgpzs
22-11-2024, 10:11 AM
» Replies: 0
» Views: 24
Rule 0.1.2
Forum: 4.0 Language independent issues
Last Post: stephanmuench
21-11-2024, 01:12 PM
» Replies: 0
» Views: 35
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
23-10-2024, 12:04 PM
» Replies: 2
» Views: 369
A8-4-5: are partial moves...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
22-10-2024, 02:03 PM
» Replies: 1
» Views: 324
model information blocks ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:27 PM
» Replies: 1
» Views: 4,441
MISRA AL SLSF - Rule 043I
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:11 PM
» Replies: 1
» Views: 8,860
MISRA AC EC guidelines
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:21 AM
» Replies: 4
» Views: 15,498
News on future releases
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:05 AM
» Replies: 1
» Views: 5,690
Signal naming convention ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 07:57 AM
» Replies: 1
» Views: 7,246
Rule 7.0.2: operator cons...
Forum: 4.7 Standard conversions
Last Post: karos
14-10-2024, 08:52 PM
» Replies: 2
» Views: 430