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

Username
  

Password
  





  MISRA C Exemplar suite : Compilation errors
Posted by: tarun.g - 24-10-2012, 07:35 AM - Forum: MISRA-C:2004 Exemplar Suite - Replies (1)

I encountered a few cases in the exemplar suite(the list mentioned below) where in any standard compiler throws an error.
1. mc2_1101.c
2. mc2_1102.c
3. mc2_1903.c
4. mc2_1908.c
5. mc2_1914.c
6. mc2_1917.c

Are all the cases(but the ones which explicitly mention that the compiler is to fail) in the exemplar suite, in general, expected to
be successfully compiled by a "MISRA standard complaint" compiler?

Print this item

  Is 16.4 violated if 16.3 is?
Posted by: gs - 11-10-2012, 08:23 PM - Forum: 6.16 Functions - Replies (1)

Given the following code:

Code:
void f(int);
void f(int x){}
Does this code violate rule #16.4, identifiers used in the declaration and definition of a function shall be identical? While the lack of a parameter name in the prototype violates #16.3, I am not sure if violating #16.4 is possible in that case.

Print this item

  10.1 in a macro
Posted by: borth - 02-10-2012, 06:34 AM - Forum: 6.10 Arithmetic Type Conversions - Replies (2)

Hello,


i got something like this:

[code]
#define X_MASK 0xFU
#define FOO(_a) ((_a) % 10U)
#define BAR(_b) (1U

Print this item

  0-1-8 and OO design pattern
Posted by: masha - 02-10-2012, 06:03 AM - Forum: 6.0 Language independent issues (C++) - Replies (1)

0-1-8 restricts such elegant design pattern as e. g. observer/listener (with selective handling of a subset of notifications by observer).
So is the "intended" use of empty virtual methods due to design OK? May design goals be classified as "side effect"?

Print this item

  15.2 and 'break's inside if-else
Posted by: gs - 06-09-2012, 07:26 PM - Forum: 6.15 Switch Statements - Replies (4)

Suppose I have the following code:

Code:
...
switch( x )
{
case 1:
    if( y )
        {
        ...
        break;
        }
    else
        {
        ...
        break;
        }
default:
    break;
}
...

Does this code violate rule #15.2?

Print this item

  Rule 19.3 - #include... - what about directories?
Posted by: SafeT - 20-07-2012, 04:53 PM - Forum: 6.19 Preprocessing Directives - Replies (1)

Hi,

Question about rule 19.3 -

I read this rule as forbidding constructs such as:

Code:
#include "foo/bar/baz.c"
and especially things like
Code:
#include "/usr/local/include/baz.h"
#include "C:/Windows/blah/baz.h"

because there is directory information following the #include keyword (it's not just a filename).

It's not clear to me whether or not the above example would violate rule 19.3 - can you please weigh in?

I think the use of absolute *or* relative directories on a #include line is a maintenance nightmare and can lead to unintended (read: incorrect) header files being included, especially as code is refactored and as source files are moved around.

My opinion (and my experience in safety-critical systems) is that #include directives should only specify a filename, not a path of any kind, and the build configuration should specify the appropriate directories to search, and in what order.

Can you please comment?

(David (or anyone from MISRA)) - I have some comments (such as this one) regarding the review draft copy of MISRA-C3, but I missed the deadline of May 31 for submitting comments. Is it too late? You can contact me through the email on my account or PM if that is better, thanks!)

Print this item

  Unreachable break in a case statement
Posted by: danielb - 04-07-2012, 08:14 AM - Forum: 6.15 Switch Statements - Replies (1)

I have recently come across two different rule interpretations of the following code:

Code:
switch(cond)
{
  case 0:
  {
    /* A deliberate infinite loop. */
    for ( ; ; ) { }
    
    /* Unreachable break statement. */
    break;
  }
  [ … ]
}
One MISRA checker insists on the break statement referring to rule 15.2, while the other insists that the break statement is unreachable code according to rule 14.1.

Both rules are required, however, both can not be enforced in this case. Which rule supersedes the other?

Print this item

  3-9-2 and 'bool'
Posted by: gs - 12-06-2012, 02:23 PM - Forum: 6.3 Basic concepts (C++) - Replies (4)

Is rule #3-9-2 intended to apply to the 'bool' type?

Print this item

  16.9 Reference to function pointer or not
Posted by: hele - 05-06-2012, 07:55 AM - Forum: 6.16 Functions - Replies (1)

Code:
typedef void (*fp)(STATE_MACHINE *sm, EVENT input);
struct STATE_MACHINE_
{
  fp fp_cur_state;
};

void stm_Startup   (STATE_MACHINE *sm,  EVENT input);
Code:
STM_STATE_MACHINE *sm;
sm->fp_cur_state = &stm_Startup;
or
Code:
sm->fp_cur_state = stm_Startup;
??

I have two tools to check code for Misra C.
Checking version without & to the function pointer with Tastking I get the error:
Quote:MISRA-C rule 16.9 violation: [R] function calls with no parameters should have empty parentheses
What in fact means the exact rule (I guess):
Quote:MISRA-C rule 16.9 violation: [R] A function identifier shall only be used with either a preceding &, or with a parenthesised parameter list, which may be empty.

checking with PC-Lint with & I get
Quote:sm->fp_cur_state = &stm_Startup;
stateMachine.c 72 Warning 546: Suspicious use of &

What's right? I guess functionality should be the same in both cases.

Print this item

  13.5 Loop control expression inconsistencies
Posted by: Dinesh - 30-05-2012, 10:19 AM - Forum: 6.13 Control Statement Expressions - Replies (1)

Dear Misra Committee,

Going through the previous posts on the rule 13.5, I found an inconsistency between the answers given in:
1) http://www.misra.org.uk/forum/viewtopic.php?f=69&t=272
2) http://www.misra.org.uk/forum/viewtopic.php?f=69&t=874

In the first post, the following was posted:

Quote:...
Loop Control Variable is defined as any variable occurring in the first, second or third expressions.

Loop Counter is defined as a Loop Control Variable which is,
• Initialised in the first expression or Initialised prior to first expression;
• In the second expression, the operand of a relational operator (= ); Note (1)
• In the third expression, always incremented or decremented by a constant, or an expression which evaluates to the same value for the duration of the loop;
• Not modified in the body of the loop.
...
Note 1: The equality operators (==, !=) should not be used because termination of the loop may not occur.
...

In the second post, the following example was given and was confirmed to be compliant with MISRA C 13.5.

[code]
bool Test_Index(int32_t index, int32_t bound){
return (bool)(p

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 77 online users.
» 0 Member(s) | 73 Guest(s)
Bing, Facebook, 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: 725
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: 436
M5-0-4 switch over unscop...
Forum: 6.5 Expressions (C++)
Last Post: misra cpp
25-09-2026, 01:00 PM
» Replies: 3
» Views: 538