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

Username
  

Password
  





  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

  Clarification on rule 10.6
Posted by: anuj1085 - 24-03-2015, 10:23 AM - Forum: 6.10 Arithmetic Type Conversions - Replies (1)

Is the rule only applies to "u" suffix or this rule also applies to "UL", "L" and other suffixes

Print this item

  Rule 13.2
Posted by: sundarn - 23-03-2015, 09:35 AM - Forum: MISRA-C:2004 Exemplar Suite - Replies (1)

typedef unsigned char bool;
bool sensor_status;

if(sensor_status) /*Rule 13.2*/
{
....
}
Is this a violation of rule 13.2 or could it be considered as effectively boolean ( Boolean by enforcement ).

Print this item

  Clarification of rule 2.5
Posted by: anuj1085 - 23-03-2015, 09:26 AM - Forum: 8.1 A standard C environment - Replies (1)

The unused macro in "header" files are also a violation of this rule. explanation below:

File.h:
================
#define abc 10
================

Case1:
File1.c include file.h but does not use abc
Is this a violation.

Case2:
File1.c include file.h but does not use abc
File2.c includes file.h and uses abc
Is this a violation with respect to file1.c as it includes the header file but does not uses the macro.

Print this item

  Clarification of rule 2.3 and 2.4
Posted by: anuj1085 - 13-03-2015, 11:53 AM - Forum: 8.1 A standard C environment - Replies (1)

The rules deals with unused tag and unused type declaration.

My query is whether the unused tag and unused types declared in "header" file are also violation of this rule. Example below to explain more:

content of test.h:

int16_t unusedtype (void)
{
typedef int16_t local_type;
return 67;
}

This header is included in test.c. Should the violations be reported on this.

Print this item

  Rule 11.9 : Global initialization of pointers
Posted by: Akhil - 13-03-2015, 08:51 AM - Forum: 8.11 Pointer type conversions - Replies (1)

In this case :

1. int *ptr ; // Is this compliant or non compliant
2. void foo()
3. {
4. /* Do Something. */
5. }

Global variables are initialized to 0 by default.
This means ptr is initialized to 0 automatically by compiler.

Ques : Is line 1 compliant or non compliant to Rule 11.9.

Does this rule also enforce initializing ptr to NULL for global pointers. ?

Print this item

  Rule 8.4 the combination of the tentative definitions
Posted by: satoshi - 12-03-2015, 08:12 AM - Forum: 8.8 Declarations and defnitions - Replies (1)

How should treat the combination of the tentative definitions?

Code:
int i;  /* treated as declaration ? */
int i;  /* treated as definition ? */

or...
If only tentative definitions exists, we should consider that the compatible declaration is not exist?

Print this item

  Essential type of enumerated constants
Posted by: psusi - 06-03-2015, 02:47 PM - Forum: 8.10 The essential type model - Replies (2)

What is the essential type of an enumerated constant? I believe it should be integer constant, and rule 10.3 seems to agree since it says this expression is compliant:

s8a = K1; /* constant value fits */

However, my static analyzer insists that this is a violation:

Code:
enum list {
ONE,
TWO,
THREE,
}

int c;
for( c = 0; c < THREE; c++ )  /* THREE is an integer constant so comparing it with c, an int, is not a violation */
....

Print this item

  Clarification on Rule 20.8
Posted by: anuj1085 - 05-03-2015, 12:47 PM - Forum: 8.20 Preprocessing directives - Replies (1)

In the below case

#if 10
----
#elif 20
----
#endif

Since the part of the code
#elif 20
----
#endif

Is never gonna execute, is the rule applicable to this part of code i.e the part #elif 20 will be ignored while compilation so should the violation should be reported on it ?

Print this item

  C90: Bitfield as essential boolean type
Posted by: nunterberg - 03-03-2015, 04:00 PM - Forum: 8.10 The essential type model - Replies (1)

Is it possible to declare bitfields that can be used as essentially boolean expressions in C90 without vialoating any MISRA rules?
Acording to section D.4, only a bit-field that has been implemented with an essential boolean type is essentially boolean. In C90, such a type does not exist as a "native" type. Sections 8.10.2 and D.6 allow an enumerated type as a way to define an essentially Boolean type. However, using such an enumerated type in a bitfield violates Rule 6.1.

Code:
typedef enum { false, true } bool_t;
struct {
    bool_t   flag1:1;  /* violates Rule 6.1 */
    uint16_t flag2:1;  /* compliant */
} bf;

if (bf.flag1) {        /* compliant? */
    do_something();
}
if (bf.flag2) {        /* violates Rule 14.4? */
    do_something();
}
Is there a compliant way out of this conflict or do we need to file a deviation for this use?

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 355 online users.
» 0 Member(s) | 352 Guest(s)
Bing, Google, Yandex

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: 23
Rule 0.1.2
Forum: 4.0 Language independent issues
Last Post: stephanmuench
21-11-2024, 01:12 PM
» Replies: 0
» Views: 34
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
23-10-2024, 12:04 PM
» Replies: 2
» Views: 366
A8-4-5: are partial moves...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
22-10-2024, 02:03 PM
» Replies: 1
» Views: 322
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,497
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