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

Username
  

Password
  





  Did '\000' and 000 comply with Rule 2-13-2
Posted by: longfem - 28-02-2017, 06:09 AM - Forum: 6.2 Lexical conventions (C++) - Replies (1)

Dears,
Rule 2-10-3 said that Octal constants (other than zero) and octal escape sequences (other than “\0”) shall not be used.

From the description we know that '\0' and 0 comply with the rule.
How about '\00', '\000' , 00 and 000 ?

Thanks,
Longfem

Print this item

  Rule 2.5 vs. include guards
Posted by: sg2 - 27-02-2017, 11:54 AM - Forum: 8.2 Unused code - Replies (1)

Hi.
It is not completely clear what is meant by use of a macro in Rule 2.5. There is definition of a use of an expression in the Glossary, but not of a macro.
If taken literally, rule 2.5 means that standard include guards are forbidden:

#ifndef HEADER_H
#define HEADER_H // Not used unless another #ifndef is encountered somewhere inside
...
#endif

Print this item

  Rule 21.18 (Amendment) - Use of '0'
Posted by: RichardC - 24-02-2017, 03:21 PM - Forum: 8.21 Standard libraries - Replies (2)

The rationale provided for this rule is to avoid reading or writing passed the bounds of an object argument, resulting in "undefined behavior".

The Amplification specifies that the value be "positive". However, that can be interpreted as "greater than" zero. However, according the to C standard (C99 7.21.1/2) it is well defined to call these functions with a value of 0:

Quote:Where an argument declared as size_t n specifies the length of the array for a function, n can have the value zero on a call to that function. Unless explicitly stated otherwise in the description of a particular function in this subclause, pointer arguments on such a call shall still have valid values, as described in 7.1.4. On such a call, a function that locates a character finds no occurrence, a function that compares two character sequences returns zero, and a function that copies characters copies zero characters.

1) Given that 0 has well-defined meaning, does 'positive' imply "greater than zero" or "greater than or equal to zero"?

2) If positive refers to "greater than zero", is there an example or rationale for excluding this well-defined behavior?


Many Thanks.

Print this item

  MISRA Coverage
Posted by: akedintm - 24-02-2017, 09:52 AM - Forum: General Questions - Replies (1)

I would like to adress some questions about the actual MISRA Coverage.
The main file reffered to is MISRA_C2012_Guidelines_for_the_use_of_the_C_language_in_critical_systems.
Then, as far as I understood, Safety/Security related topics brought up the new Ammendment 1 along with Addendum 1 ( Rule mapping ) and Addendum 2.

My question would be, does MISRA and the extensions above cover the entire ISO/IEC TS 17961 descriptions ?
And also, what would the difference be between MISRA with extensions and SEI CERT C Coding Standard ?

Thank you all in advance for the answers !

Best regards, Alex.

Print this item

  Let me confirm the requirement of Rule 16.1
Posted by: nakagawat - 20-02-2017, 06:17 AM - Forum: 8.16 Switch statements - Replies (6)

Dear All,

Is the following code the violation of Rule 16.1?
The code has statements after the first break statement in case 10.

// from here
typedef unsigned int uint32_t;
extern uint32_t func_a( uint32_t x );
uint32_t func_a( uint32_t x )
{
uint32_t rtn = 0;
switch( x )
{
case 10:
break;
rtn = 50; /* Rule 16.1 violation? */
break;
default:
break;
}
return rtn;
}
// to here

Best regards,

Print this item

  6.5 - variable kinds suitable for use as loop counter
Posted by: grunwald - 16-02-2017, 06:48 PM - Forum: 6.6 Statements (C++) - Replies (1)

Which of the following is a 'variable' and thus suitable for use as loop counter (and subject to the restrictions on loop-control-variables)?

  • local variable
  • static/global variable
  • class member variable
  • function parameter [code]void f(int x) { for (; x

Print this item

  -32768 on 16-bit targets
Posted by: grunwald - 14-02-2017, 06:00 PM - Forum: 8.10 The essential type model - Replies (1)

Just to make sure since several of our customers brought this up lately:

Is the following code compliant on a target where 'int' is 16 bits?

Code:
int16_t x = -32768;

Since the standard C type of '-32768' is 'long' on 16-bit targets, the essential type is the same.
Thus, I believe the code is not compliant.

This seems unfortunate given that the value does fit in the target type; especially since the same code is compliant on targets with 32-bit int.

Print this item

  5-2-7 reinterpret_cast between derived classes?
Posted by: paetzold - 13-02-2017, 04:31 PM - Forum: 6.5 Expressions (C++) - Replies (3)

Dear MISRA team,

the term "unrelated type" leads to the question whether casting from a base to derived class pointer type and vice versa using reinterpret_cast shall be covered by the rule or not. Remark: I am perfectly aware that dynamic_cast and static_cast , resp., would be the right way for these purposes, so my question is rather academic.

I refer to the term "related type" as Stroustrup uses it concerning types "in the same class hierarchy" which is surely the case here.

Code:
class B {};
class D : public B {};

void f()
{
    D* dptr = new D();
    B* bptr = reinterpret_cast( dptr );
    D* dptr2 = reinterpret_cast( bptr ); // correct (yet ugly) when one knows where the base class pointer points to
}

Print this item

  Rule 0-1-3/0-1-4/0-1-5 and (template) class members
Posted by: grunwald - 01-02-2017, 06:11 PM - Forum: 6.0 Language independent issues (C++) - Replies (1)

Do these rules apply to class members?

If so, do they apply to instances of template class members?

Code:
template
class C {
    T member1; // never used; compliant with 0-1-3?
    T member2; // C::member2 is used but C::member2 is not; compliant with 0-1-3?

    typedef T Unused; // typedef never used: non-compliant with 0-1-5.
    typedef T X; // C::X is used but C::X is not; compliant with 0-1-5?

    void call() { // only instantiated for C
       use(static_cast(member2));
    }
};

int main() {
  C().call();
  C();
}

The same question also applies to 0-1-4.

For 0-1-10 the situation is different, as class template member functions only get instantiated if they actually used. Thus C::call() is compliant with 0-1-10. A completely unused class template member function would be non-compliant with Rule 14-7-1.

Print this item

  Rule 8-5-2 what is "non-zero initialization"?
Posted by: grunwald - 24-01-2017, 02:21 PM - Forum: 6.8 Declarators (C++) - Replies (1)

C++ has the concepts:

  • default initialization ("T var;")
    Calls the default constructor (if it exists); otherwise the memory is left uninitialized.

  • value initialization ("T var = {};")
    Calls the default constructor if it exists and is user-defined.
    Otherwise, performs zero-initialization and then calls the compiler-generated default constructor (if it exists).

  • zero initialization
    Roughly equivalent to a memset(..., 0, ...)

The term "non-zero initialization" is not defined anywhere.

Code:
struct POD { int member1; int member2; };
class UserDefinedCtor { public: UserDefinedCtor(); };
struct CompilerDefinedCtor { int member1; UserDefinedCtor member2; };

POD pod[3] = {}; // value initialization that uses zero initialization
UserDefinedCtor udc[3] = {}; // value initialization but does not involve zero initialization
CompilerDefinedCtor cdc[3] = {}; // value initialization that involves both zero initialization and constructor calls

The declaration `pod` is clearly compliant with Rule 8-5-2.

What about `udc`? If it is classified as "non-zero initialization", Rule 8-5-2 would require an explicit initializator for each element:
Code:
UserDefinedCtor udc[3] = { UserDefinedCtor(), UserDefinedCtor(), UserDefinedCtor() };

But maybe "zero initialization" in this rule does not refer to the C++ concept, but instead to the syntactic forms "{}", "{0}" and "{NULL}" ?

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 378 online users.
» 0 Member(s) | 375 Guest(s)
Applebot, Bing, Google

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