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

Username
  

Password
  





  Suggested exception for rule 8.12
Posted by: psusi - 26-02-2015, 03:53 PM - Forum: 8.8 Declarations and defnitions - Replies (1)

Rule 8.12 : Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique

The purpose of this rule is clearly to catch two enumerated constants that are *accidentally* assigned the same value. To this end, it makes sense to flag two constants with the same value, where one is auto assigned and one is manually assigned. However, I sometimes employ a paradigm that triggers a violation of this rule where I feel it is extremely clear that the duplicate assignment is not accidental, and so it would be nice to have an exception for this in future editions of the standard. It looks like this:

Code:
enum {
    FIRST_GROUP_ONE,
    TYPE1 = FIRST_GROUP_ONE,
    TYPE2,
    TYPE3,
    LAST_GROUP_ONE = TYPE3,
    FIRST_GROUP_TWO,
    TYPE4 = FIRST_GROUP_TWO,
    TYPE5,
    LAST_GROUP_TWO = TYPE5
}

The symbols LAST_GROUP_ONE and LAST_VALUE are obviously assigned the same numeric value as TYPE3 and TYPE5 respectively, without regard to what that actual numeric value is. This purpose for this is to allow writing loops to iterate over the set or sub sets of the listed types in the enum or to test whether a value is on one subset or another. Explicitly assigning one symbolic name to the other could not possibly be an accident, so I think it makes a good exception to this rule.

Print this item

  Recommendations to resolve issue 12.4
Posted by: jbrookley - 25-02-2015, 10:16 PM - Forum: 6.12 Expressions - Replies (1)

Hello,

I had a question regarding rule 12.4 and realize I asked a similar question here:

http://www.misra-c.com/forum/viewtopic.php?f=68&t=1296

I didn't want to bump an old thread so I started a new one (hopefully, that's ok).

I received an error for rule 12-4 with the following section of code:

Code:
if((CommandState!=7u)&&(CommandState!=8u)&&(CommandState!=9u)&&(CommandState!=10u)&&(CommandState!=11u)&&(commData==0x24u)) /* Please ignore the fact this is written inefficiently for now */
{
        CommandState = 0u;
}

I resolved this issue using the following section of code but I wasn't sure if this is the best way to handle the code or if it's recommended to handle it using a different technique:

[code]if(commData==0x24u)
{
if(CommandState>=7u)
{
if(CommandState

Print this item

  MISRA C:2012 on Auto Code
Posted by: sundarn - 21-02-2015, 06:34 AM - Forum: MISRA C:2004 to MISRA C:2012 migration - Replies (1)

MISRA C:2004 had an additional document MISRA AC AGC explaining the application of MISRA-C 2004 in the context of automatic code generation and it do gives applicability of the rule on Model level with MOD category. In MISRA C:2012 a small section is added to explain the applicability on auto code in Appendix E where i could not find any details on the action required at model level. If i am moving from MISRA C:2004 to MISRA C:20012 what rules should i take to address at model level. Will MISRA be releasing any document in this regard.

Print this item

  Rule 8.9
Posted by: anuj1085 - 18-02-2015, 12:46 PM - Forum: 8.8 Declarations and defnitions - Replies (1)

Below is my query:

# file1 a.c includes a # file 2 a.h
================================

#file2 a.h contains following code snippet
-------------------------------------------------------------
extern int eix;
static int siz;

eix and siz are not referenced from anywhere i.e. they are unused. So should the violation for this rule should be reported on these variables as well or the violation shoudl only be reported if the variable is used somewhere in the code.

Print this item

  What is the essential type of -123L?
Posted by: misra-c - 17-02-2015, 01:26 PM - Forum: 8.10 The essential type model - Replies (1)

When applying the essential type model, what is the essential type of "-123L"?

Print this item

  Rule 20.3 space after #include
Posted by: misra-c - 13-02-2015, 12:36 PM - Forum: 8.20 Preprocessing directives - Replies (1)

The amplification to rule 20.3 states that the rule applies "after macro replacement" has been performed. Is the number/absence of spaces and comments between #include and the " or < irrelevant?

So for example:

Code:
#include              /* no space - compliant ? */
#include/* comment*/  /* compliant  ? */.

Print this item

  Rule 14.2 What is meant by assign"
Posted by: misra-c - 13-02-2015, 12:15 PM - Forum: 8.14 Control statement expressions - Replies (1)

In the 1st clause what is meant by “assign a value to the loop counter”. May this “value” be an expression with side-effects?

Code:
int index;
for ( set_val(&index) ;  index < 10 ; index++) // Is this compliant if set_val assigns to index
Note: the 2nd and 3rd clauses explicitly refer to expressions and whether side-effects are permitted.

Print this item

  8.10.3 Are increment operator composite?
Posted by: misra-c - 13-02-2015, 10:13 AM - Forum: 8.10 The essential type model - Replies (1)

Are post-fix and pre-fix increment and decrement operators treated as composite operators?

Print this item

  Rule 10.2 Are increment/decrement compliant
Posted by: misra-c - 13-02-2015, 10:01 AM - Forum: 8.10 The essential type model - Replies (1)

Are the increment and decrement operators on essentially character type allowed?

Code:
char c = ‘A’;
   c++;  /* compliant or not compliant */

Print this item

  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

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,204
» Latest member: domarant
» Forum threads: 1,017
» Forum posts: 2,796

Full Statistics

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

Latest Threads
Rule 7.0.5, example non-c...
Forum: 4.7 Standard conversions
Last Post: cgpzs
17-04-2025, 12:10 PM
» Replies: 0
» Views: 171
A3-3-2 Contradictory exam...
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
31-03-2025, 09:30 AM
» Replies: 2
» Views: 298
16.6.1 clarification
Forum: 4.16 Overloading
Last Post: cgpzs
31-03-2025, 09:29 AM
» Replies: 2
» Views: 285
Rule 9.3.1 - iteration st...
Forum: 4.9 Statements
Last Post: misra cpp
28-03-2025, 01:17 PM
» Replies: 1
» Views: 189
Rule 8.2.8 - why aren't a...
Forum: 4.8 Expressions
Last Post: misra cpp
28-03-2025, 01:05 PM
» Replies: 1
» Views: 208
Typo in Appendix C of MIS...
Forum: 8.10 The essential type model
Last Post: Yordan Naydenov
17-03-2025, 02:58 PM
» Replies: 0
» Views: 164
Adopted modal expressions...
Forum: General Questions
Last Post: Yordan Naydenov
17-03-2025, 09:01 AM
» Replies: 0
» Views: 262
Roadmap to c23 support
Forum: General Questions
Last Post: ACHart
28-02-2025, 03:23 PM
» Replies: 0
» Views: 212
Rule 6.2.1 weak linkage
Forum: 4.6 Basic concepts
Last Post: misra cpp
28-02-2025, 01:04 PM
» Replies: 1
» Views: 268
A8-4-5: Should have an ex...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
21-02-2025, 12:58 PM
» Replies: 3
» Views: 697