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

Username
  

Password
  





  Rule 5.4: Macro identifier
Posted by: Polyspacer - 16-06-2015, 12:01 PM - Forum: 8.5 Identifers - Replies (1)

I have a question regarding rule 5.4: Which of the following #defines is violating this rule?

Code:
#define  engine_exhaust_gas_temperature_high_raw     egt_r
#define  engine_exhaust_gas_temperature_high_scaled  egt_s

#define x 0
#define x 0

#ifndef ABCDE
#define DAI_AGK_SEC_1BIT_RAM_START
#endif

#ifndef FGHIJ
#define DAI_AGK_SEC_1BIT_RAM_START
#endif

unsigned long int A;
unsigned short int Con = 0;

void main(void)
{

    /*5.4*/
    #ifdef DAI_AGK_SEC_1BIT_RAM_START
    A = Con;
    #endif
    A = x;
    
}

The 1st and 2nd #define are similar to the example given in the MISRA-C guideline. Hence, the 2nd #define violates the rule.
The 3rd and 4th #define are identical. Therefore, the 4th #define violates the rule.
The 5th and 6th #define are identical as well. Does the 6th #define violate the rule? According to the glossary, the macro name is a macro identifier...

Print this item

  How to fix Warnings 10.1 and 10.3
Posted by: chas - 12-06-2015, 06:58 PM - Forum: 6.10 Arithmetic Type Conversions - Replies (1)

Hi. We're new to MISRA-2004. Can anyone explain why I get these warnings and how to fix them. We are using Code Composer.

unsigned int x = 0U;
unsigned int* px;

px = &x; /* 10.1 warning */
px = (unsigned int*)&x; /* 10.3 warning */

Print this item

  8.10.3 Is ~ operator composite?
Posted by: miyanom - 04-06-2015, 02:27 AM - Forum: 8.10 The essential type model - Replies (1)

In 8.10.3, ~ operator is not defined as a composite operator.
Is it necessary to treat ~ operator as composite?

If ~ operator is not composite, then is the following code compliant with Rule 10.6?
u16a = ~u8a;

Print this item

  Rule 11.1, 11.2 (and others?) vs conversion caused by equality operators (and similar)?
Posted by: pkruk - 03-06-2015, 02:14 PM - Forum: 8.11 Pointer type conversions - Replies (1)

Hello,

rules 11.1 and 11.2 disallow conversions between pointer to a function or incomplete type, and any other type:

Code:
void (*fp1)(short);
void (*fp2)(int);

fp2 = fp1;          /* Not-compliant - different function */
fp2 = 0x8000;       /* Not-compliant - integer */

What if the conversion happens for example in equality operator:
Code:
fp2 == fp1;         /* Compliant or Not-compliant ? */
fp2 != 0x8000;      /* Compliant or Not-compliant ? */

Following example from Rule 11.1 suggests it's also non-compliant:
Code:
if ( fp2 != NULL )  /* Compliant - exception 1 (NULL) */

Print this item

  Loops violate Rule 14.3
Posted by: chrisT - 02-06-2015, 10:20 AM - Forum: 6.14 Control Flow - Replies (2)

Hello.

In our company, we have developers who uses

Code:
for(;;)
loops. Are these a violation against rule 14.3?

kind regards.

Print this item

  RSS support gone
Posted by: cweimer - 22-05-2015, 04:03 PM - Forum: General Questions - Replies (1)

Seems your upgrade of phpBB has erased rss support (Smartfeed), was this intended?
Thanks

Print this item

  Example at 11.1 and 11.2
Posted by: ogawa.kiyoshi - 29-04-2015, 09:24 AM - Forum: 8.11 Pointer type conversions - Replies (1)

In example codes in Rule 11.1 and Rule 11.2

#include /* to obtain macro NULL */

in example codes in 11.9

#include

A freestanding environment needs stdarg.h not sodlib.h.
So I prefer to obtain macro NULL,
#include // to obtain macro NULL

Is it reasonable?

ps. in 11.9
/* Could also be stdio.h, stdlib.h and others */

I prefer
/* A free standing environment needs stddef.h */
/* Could also be stdio.h, stdlib.h and others in host environments */

Best Regards.

Print this item

  Rule 2.4 and forward declarations
Posted by: michael.metivier - 21-04-2015, 10:08 PM - Forum: 8.2 Unused code - Replies (2)

Would the use of tags for forward declarations be considered a failure of this rule, if used such as

Code:
struct test;
typedef struct test test_T;

typedef bool (*Callback_T)(test_T const * p_test);

struct test
{
    uint32_t var;
    Callback_T callback;
};
For consistency in type usage, I would prefer to utilize the typedef whenever referring to this structure, including in the callback definition, but this leads our analysis tools to flag that "test" is only used in the typedef.

Print this item

  Clarification for Rule 6.1
Posted by: anuj1085 - 06-04-2015, 09:02 AM - Forum: 6.6 Types - Replies (1)

The rule says that the plain char should only be used to store character values.

C standards says single character constant for eg. 'X' are int not char. So the following code:

char x = 'A';

is a violation of the rule as in this char x is storing a constant whose type is "int". If this is not the violation then how to interpret this rule as the all single character constants are int according to "c" standards.

Print this item

  R.13.5 When does a function have persistent side effects
Posted by: misra-c - 27-03-2015, 01:28 PM - Forum: 8.13 Side effects - Replies (1)

Consider the following example:

Code:
bool fn ( int x )
{
   static int y;
   if ( x > 0 )
   {   y = x;  }  /* causes persistent side effect if reached */
   return ....
}

void call ( bool flag )
{
    if ( flag &&  fn(-3) ) /* Does RHS contain persistent side effect ? */
    { .... }
}
In this example the call of "fn(-3)" never executes the code "y=x" and therefore no persistent side effect will occur.
Is this a violation of rule 13.5?

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 222 online users.
» 0 Member(s) | 219 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: 170
A3-3-2 Contradictory exam...
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
31-03-2025, 09:30 AM
» Replies: 2
» Views: 297
16.6.1 clarification
Forum: 4.16 Overloading
Last Post: cgpzs
31-03-2025, 09:29 AM
» Replies: 2
» Views: 280
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: 211
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: 695