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

Username
  

Password
  





  10.3 and storing enums in integers
Posted by: psusi - 27-02-2015, 08:54 PM - Forum: 8.10 The essential type model - Replies (3)

Looking at the table for rule 10.1, the essential type of an enum and an unsigned integer differ, and rule 10.3 states that "The value of an expression shall not be assigned to an object with a
narrower essential type or of a different essential type category". I would think that means that you can not assign an enum to a signed or unsigned integer type, but the example section shows this as not violating the rule:

Code:
s8a = K1;    /* Constant value fits */

Why is this OK?

Print this item

  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

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 336 online users.
» 0 Member(s) | 334 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