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,196
» Latest member: galibl1
» Forum threads: 1,008
» Forum posts: 2,779

Full Statistics

Online Users
There are currently 249 online users.
» 0 Member(s) | 247 Guest(s)
Bing, Google

Latest Threads
A8-4-5: Should have an ex...
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
Yesterday, 02:14 PM
» Replies: 2
» Views: 119
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
14-02-2025, 01:04 PM
» Replies: 3
» Views: 1,204
Rule 3-4-1 and lifetimes,...
Forum: 6.3 Basic concepts (C++)
Last Post: misra cpp
14-02-2025, 01:02 PM
» Replies: 1
» Views: 87
Application of Rule 15.0....
Forum: 4.15 Special member functions
Last Post: misra cpp
07-02-2025, 12:44 PM
» Replies: 3
» Views: 2,576
Rule 6.2.1: non-inline co...
Forum: 4.6 Basic concepts
Last Post: misra cpp
07-02-2025, 12:43 PM
» Replies: 3
» Views: 739
A7-2-1 Still relevant in ...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
31-01-2025, 01:20 PM
» Replies: 1
» Views: 206
MISRA AC INT:2025
Forum: MISRA AC resources
Last Post: misra-ac
22-01-2025, 03:37 PM
» Replies: 0
» Views: 147
MISRA AC SLSF:2023 AMD3
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
13-01-2025, 10:58 AM
» Replies: 0
» Views: 199
MISRA AC SLSF:2023 AMD3
Forum: MISRA AC resources
Last Post: misra-ac
13-01-2025, 10:57 AM
» Replies: 0
» Views: 193
Rule 7.0.4 - exception fo...
Forum: 4.7 Standard conversions
Last Post: misra cpp
10-01-2025, 02:26 PM
» Replies: 4
» Views: 836