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

Username
  

Password
  





  macro contains unaceptable items misra c 2004 19.4
Posted by: manojkdi - 31-07-2013, 11:35 AM - Forum: 6.19 Preprocessing Directives - Replies (1)

Example

#define MACRO_2 1(this macro is defined in some other file)

#define MACRO_1 MACRO_2

this statement is causing the warning in "macro contains unacceptable items misra c 2004 19.4".Is this warning valid? Is it really a invalid macro definition?

Print this item

  1-bit bitfield in boolean expression
Posted by: holger_l - 22-07-2013, 08:53 AM - Forum: 6.13 Control Statement Expressions - Replies (2)

Hi,
rule 13.2 makes an example how boolean data could be used in an expression:

Code:
if ( y ) /* Not compliant, unless y is effectively Boolean data (e.g. a flag) */
The example refers to a Boolean-by-enforcement type referred to in the appendix.
But what is with a 1-bit Bitfield? Is it a Boolean-by-construct?
Code:
struct { unsigned int flag1: 1, flag2: 1;} var;
...
if (var.flag1)                   /* violation of rule 13.2 ? */
if (( var.flag1) && (var.flag2)) /* violation of rule 12.6 ? */
if ((!var.flag1) && (var.flag2)) /* 2x violation of rule 12.6 ? */
if ((var.flag1 == 0) && (var.flag2 != 0)) /* OK, but clumsy and harder to read */
Thanks for a comment!

Print this item

  Conditional stream opening and 22.3?
Posted by: gs - 12-07-2013, 04:05 PM - Forum: 8.22 Resources - Replies (1)

Does the rule prohibit cases like the following:

Code:
if( someCondition )
    f = fopen( "apple", "r+" );
else
    f = fopen( "apple", "r" );
g = fopen( "apple", "r+" );

Print this item

  Essential Type Category of Complex Floating Types?
Posted by: gs - 27-06-2013, 05:11 PM - Forum: 8.10 The essential type model - Replies (2)

C99 provides for complex floating point types. What is the essential type category of each?

Print this item

  Floating point test for equality
Posted by: richardb - 26-06-2013, 11:16 AM - Forum: 8.10 The essential type model - Replies (2)

The previous MISRA version (2004) explicitly banned the use of tests for equality on floating point numbers (MISRA C 2004 rule 13.3).
MISRA C:2012 has a list of operands and essential types to avoid in the table in rule 10.1, but the use of the equality operator, ==, on the essential type floating is not restricted.
Could I suggest this is an unintentional omission?
Richard.

Print this item

  Rules 13.4 Function call with float
Posted by: Bfr - 25-06-2013, 02:34 PM - Forum: 6.13 Control Statement Expressions - Replies (1)

Hello,

As the rule 13.4 says : The controlling expression of a for statement shall not contain any objects of floating type.

But what about a function call with a float as parameter (example below) ?

I am asking this in order to implement a MISRA rule checker.

Code:
int32_t i = 0;
float32_t float_var;

[...]

for (i = 0; i < float_to_int(float_var); ++i)
{
[...]
}

It seems correct to me since the float is not really use in the controlling expression. But the rules says any objects and that confuse me a little.

Thanks,
Ben

Print this item

  Example for Rule8.10 (inline function)
Posted by: Wolfgang Gebauer - 20-06-2013, 09:35 AM - Forum: 8.8 Declarations and defnitions - Replies (1)

Hello,

I have a question regarding the Rule 8.10.
Usually in our code we implement inline functions in header files.
Therefore these inline functions are already visible in many modules.
How can these inline function be made static?
Is it necessary to implement these inline functions as static in header files?
example:

header_file.h
inline void function1(int a, int b)
{
...
return;
}

c_file1.c
include
void function3(void)
{
function1(a_param, b_param);
...
return;
}

Can somebody give me a solution?

Regards
Wolfgang

Print this item

  Rule 19.4 do-while(0) for single statements
Posted by: wwinzer - 28-05-2013, 06:24 AM - Forum: 6.19 Preprocessing Directives - Replies (2)

While I fully understand the need to weld multiple statements in a function-like macro into a compound statement using the do-while(0) construct, I wonder why rule 19.4 explicitely includes macros with only one statement.

Quote: The do-while-zero construct is used to wrap a series of one or more statements and ensure correct behaviour.

I've searched the net high and low and could not find any reason for requiring single statements to be encapsulated in do-while(0). Could you give an example here of code that breaks when disregarding this rule?

Print this item

  8.14 and "involved in a decision to exit the loop"
Posted by: gs - 01-05-2013, 02:23 PM - Forum: 8.14 Control statement expressions - Replies (1)

Section 8.14 defines a loop counter as "an object, array element or member of a structure or union which"

  • 1. has scalar type,
    2. varies monotonically on each iteration of a given instance of a loop, and
    3. is involved in a decision to exit the loop.
My question is, "To what extent does the item in question need to be "involved in a decision to exit the loop"? For example, consider the code:
Code:
...
if( g(x) )
    break;
...
Is 'x' "involved in a decision to exit the loop"?

What of
Code:
...
if( h() )
    break;
...
where 'h()' returns a value based on, say, a static variable, 'q'; is 'q' "involved in a decision to exit the loop"?

Print this item

  Appendix B - mapping of rule 10.2
Posted by: andream - 23-04-2013, 09:41 AM - Forum: 6.10 Arithmetic Type Conversions - Replies (1)

It seems there is a minor inconsistency in MISRA-C 2004. At top of pag. 103 (Appendix B) I can read that rule 77 in MISRA-C 1998 is mapped onto rule 10.2 in MISRA-C 2004. Indeed this latter is as duly reported in third column ("The value of an expression of floating type..."), but corresponding rule 77 in MISRA C 1998 is well different:

"The unqualifed type of parameters passed to a function shall be compatible with the unqualified expected types defined in the function prototype".

Can you help me?

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 349 online users.
» 0 Member(s) | 346 Guest(s)
Applebot, Bing, Google

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: 26
Rule 0.1.2
Forum: 4.0 Language independent issues
Last Post: stephanmuench
21-11-2024, 01:12 PM
» Replies: 0
» Views: 36
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
23-10-2024, 12:04 PM
» Replies: 2
» Views: 382
A8-4-5: are partial moves...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
22-10-2024, 02:03 PM
» Replies: 1
» Views: 329
model information blocks ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:27 PM
» Replies: 1
» Views: 4,446
MISRA AL SLSF - Rule 043I
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:11 PM
» Replies: 1
» Views: 8,863
MISRA AC EC guidelines
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:21 AM
» Replies: 4
» Views: 15,507
News on future releases
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:05 AM
» Replies: 1
» Views: 5,694
Signal naming convention ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 07:57 AM
» Replies: 1
» Views: 7,249
Rule 7.0.2: operator cons...
Forum: 4.7 Standard conversions
Last Post: karos
14-10-2024, 08:52 PM
» Replies: 2
» Views: 438