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

Username
  

Password
  





  10.3 Clarification on assigning unsigned literal to signed
Posted by: michael.metivier - 08-02-2016, 02:54 PM - Forum: 8.10 The essential type model - Replies (3)

Quote:A non-negative integer constant expression of essentially signed type may be assigned to an object of essentially unsigned type if its value can be represented in that type.

While Rule 10.3 has this Exception for constructions similar to
Code:
uint8_t u8a = 0;    /* By exception */
there does not seem to be a similar exception for the inverse
Code:
int8_t s8a = 1u;    /* Compliant? */
Our current analysis tool flags this as an error, but this assignment seems no more dangerous than the one given by the Example. Is there a specific rationale for why this assignment should not be allowed, given the condition of the Exception
Quote:if its value can be represented in that type.
?

Print this item

  Rule 2-10-6
Posted by: Mats Fors - 26-01-2016, 09:04 AM - Forum: 6.2 Lexical conventions (C++) - Replies (1)

Shouldn't example one be compliant?

typedef struct vector {...} vector;

The two vector identifiers are both referring to the same type.

Print this item

  Rule 16-0-1 and extern "C"
Posted by: detra - 14-01-2016, 08:45 AM - Forum: 6.16 Preprocessing directives (C++) - Replies (2)

Hello,
if we want to use the same Header files for "C" and "C++" we must use the "extern C" constuct. But the "extern C" construct must be placed before the include of the Header and so our tool reports a MISRA 16-0-1 violation. Is this violation valid? And if so, is there an other solution?

Code:
#ifndef _MYHEADER_
#define _MYHEADER_

extern "C"
{
    #include "firstheader.h"                // MISRA 16-0-1 violation
}

Thank you for help,
Stefan

Print this item

  Code generators for MISRA C++
Posted by: Insane Vent Storm - 04-01-2016, 12:55 PM - Forum: C++ General - No Replies

On the general subject of MISRA compliance and auto-code, is anyone out there using a code generating tool and trying to produce MISRA C++ 2008 compliant code ?

Print this item

  Essential type of constant expressions
Posted by: roberto - 27-12-2015, 05:06 PM - Forum: 8.10 The essential type model - Replies (1)

In MISRA-C:2012, it is stated that the essential type of the constant expression ~(unsigned short)3 is the UTLR of its value (i.e., -4), but the definition of UTLR seems not to cover this case (that is, the UTLR of -4 is undefined).

Another similar example is (unsigned char)3 - (unsigned char)4.

What is the essential type of these constant expressions?

Print this item

  15.7 and side effects
Posted by: lovewar - 11-12-2015, 12:08 AM - Forum: 8.15 Control flow - Replies (2)

Would the following examples be compliant with rule #15.7?

Code:
void R_15_7 ( void ) {
   bool_t flag_1 = get_bool ( );
   bool_t flag_2 = get_bool ( );
   if ( flag_1 )  {
      action_f1 ( );
   }
   else if ( flag_2 )  {
      action_f2 ( );
   }
   else {  // here , is the "else" compliant ?
      persistent_side_effects();
  }
}

Would the following examples be compliant with rule #15.7?
Code:
void R_15_7 ( void ) {
   bool_t flag_1 = get_bool ( );
   bool_t flag_2 = get_bool ( );
   if ( flag_1 )  {
      action_f1 ( );
   }
   else if ( flag_2 )  {
      action_f2 ( );
   }
   else {  // here , is the "else" compliant ?
      side_effects();
  }
}

Would the following examples be non-compliant with rule #15.7?
Code:
void R_15_7 ( void ) {
   bool_t flag_1 = get_bool ( );
   bool_t flag_2 = get_bool ( );
   if ( flag_1 )  {
      action_f1 ( );
   }
   else if ( flag_2 )  {
      action_f2 ( );
   }
   else {  // here, is the "else" non-compliant ?
      no_side_effects();
  }
}

Print this item

  Rule 19.1 and assigment between members of a struct
Posted by: GerlindeKettl - 20-11-2015, 10:34 AM - Forum: 8.19 Overlapping storage - Replies (1)

Does this code violate rule 19.1?

Code:
struct s_tag {  
uint8 ReadPos;
uint8 WritePos; };
typedef struct s_tag s;

union u_tag {
s      Elements;
uint32 Value; };
typedef union u_tag u;

u NewState;
NewState.Elements.ReadPos  = NewState.Elements.WritePos;
My static code checker thinks it is a violation, but from my point of view I'm just assigning one member of a struct to a different member of the struct and they don't overlap in memory. That this struct is a member of a union should not matter as there is no assignment across the members of the union.

Print this item

  MISRA C 2012 rule 8.6
Posted by: mcorles5 - 18-11-2015, 02:00 PM - Forum: General Questions - Replies (1)

The rule definition is "An identifier with external linkage shall have exactly one external definition." When I look at where it says there are multiple definitions, it points to the same line.
Ie.
global variable 'CALIBRATION_MISMATCH' has multiple tentatives of definitions (C:\User\Desktop\globals.c:137, C:\Users\Desktop\globals.c:137) (Required)
U8 CALIBRATION_MISMATCH;

Print this item

  Making constants in MISRA compliant C++
Posted by: Insane Vent Storm - 09-11-2015, 01:52 PM - Forum: 6.1 General (C++) - Replies (8)

I am trying to declare a constant for use in fixing the size of several C++ arrays. I have tried 3 options:
1) #'define MaxTracksConst 8

2) const Rhp_int32_t MaxTracksConst(8);

3) enum %s {one, two, three, four, five, six, seven, MaxTracksConst}

but our LDRA MISRA checker finds fault with all of them ( 1. fails 16-2-2, 2. fails 3-1-1 and 3. fails 4-5-2 ).
Am I missing something, or is there an option that will pass MISRA C++ 2008 checks ?

Kind regards
Insane Vent Storm

Print this item

  Rule 8.4: Prototype for function with internal linkage required?
Posted by: aletomm - 04-11-2015, 02:51 PM - Forum: 8.8 Declarations and defnitions - Replies (1)

Does MISRA-C 2012 mandate prototypes for functions with internal linkage?

While MISRA-C 2012 rule 8.4 is very explicit about prototypes for functions with external linkage, we have not found a corresponding rule for internally linked functions.

Our static analysis tool takes the simplistic approach that prototypes are required in any case due to MISRA-C 2004 8.1 rule. I like to challenge its reasoning.

Thanks.

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,309
» Latest member: 1fuhd
» Forum threads: 1,066
» Forum posts: 2,933

Full Statistics

Online Users
There are currently 95 online users.
» 0 Member(s) | 92 Guest(s)
Bing, Google, UptimeRobot

Latest Threads
13.2 Was TC2 correctly ap...
Forum: 8.13 Side effects
Last Post: misra-c
08-10-2026, 12:47 PM
» Replies: 1
» Views: 625
20.12 Does the stringific...
Forum: 8.20 Preprocessing directives
Last Post: misra-c
08-10-2026, 12:40 PM
» Replies: 1
» Views: 554
13.3 Should side effects ...
Forum: 8.13 Side effects
Last Post: misra-c
08-10-2026, 12:37 PM
» Replies: 1
» Views: 428
11.6 pointer to pointer t...
Forum: 8.11 Pointer type conversions
Last Post: misra-c
08-10-2026, 12:21 PM
» Replies: 2
» Views: 1,032
What is the UTLR of -1?
Forum: 8.10 The essential type model
Last Post: misra-c
08-10-2026, 12:15 PM
» Replies: 1
» Views: 597
10.3 Clarify if narrower ...
Forum: 8.10 The essential type model
Last Post: misra-c
08-10-2026, 11:57 AM
» Replies: 1
» Views: 508
It 8.12 intended to be so...
Forum: 8.8 Declarations and defnitions
Last Post: misra-c
08-10-2026, 11:50 AM
» Replies: 1
» Views: 455
Rule 0.1.1 Example f4
Forum: 4.0 Language independent issues
Last Post: cgpzs
07-10-2026, 11:07 AM
» Replies: 3
» Views: 727
Rule 6-2-2 Usage of std::...
Forum: 6.6 Statements (C++)
Last Post: misra cpp
25-09-2026, 05:43 PM
» Replies: 1
» Views: 437
M5-0-4 switch over unscop...
Forum: 6.5 Expressions (C++)
Last Post: misra cpp
25-09-2026, 01:00 PM
» Replies: 3
» Views: 539