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

Username
  

Password
  





  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

  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

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 242 online users.
» 0 Member(s) | 238 Guest(s)
Applebot, 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: 281
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