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

Username
  

Password
  





  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

  Pointer conversions (implicit, explicit, void)
Posted by: Gabe - 25-05-2012, 04:19 PM - Forum: 6.11 Pointer Type Conversions - Replies (1)

I would like to ask for some help interpreting MISRA-C:2004. I have a few very simple examples. Please confirm whether my observations below are correct.

1)
#include
void main(void) {
char* string = "Hello World!";
int* result = string;
printf("Result: %d\n", *result);
}

This code is not MISRA-C:2004 compliant, because the implicit pointer conversion is not legal ANSI C. Thus, it violates rule 1.1. Is this observation correct?

2)
#include
void main(void) {
char* string = "Hello World!";
int* result = (int*)string;
printf("Result: %d\n", *result);
}

This code is MISRA-C:2004 compliant. However, the explicit type cast to int* is a violation of advisory rule 11.4. Is this observation correct?

3)
#include
void main(void) {
char* string = "Hello World!";
void* void_ptr = string;
int* result = void_ptr;
printf("Result: %d\n", *result);
}

This code is MISRA-C:2004 compliant. It also does not violate advisory rule 11.4. Is this observation correct?

4)
#include
void main(void) {
char* string = "Hello World!";
void* void_ptr = (void*)string;
int* result = void_ptr;
printf("Result: %d\n", *result);
}

This code is MISRA-C:2004 compliant. However, it now does violate advisory rule 11.4 due to the use of the type cast operator. Is this observation correct?

I do not see how 3) is better than alternative 2) or 4) above. Double casting through void pointers does not seem to be safe practice. It hides the conversion intent, so it makes the code harder to read.

I understand that the main reason for allowing conversions to void pointers is due to legacy reasons (i.e. writing data to memory). Seeing that 11.4 is advisory, would it not be better to refer to "conversions" between different pointers to object, rather than "casting"?

Print this item

  meaning of 045G MISRA AC SLSF
Posted by: stefania.botta - 08-05-2012, 07:25 AM - Forum: MISRA AC SLSF discussions - Replies (1)

Hi,

I write you, because I can not understand the meaning of 045G MISRA AC SLSF. The doubt is this: the rule want there are no variables written when transitioning between any states, in any case (I think it is very strong as assertion). Or the rule is specific when you are using condition-action and transition-action (deviation from 043A MISRA AC SLSF) when transitioning between any states. Or is there another meaning for understanding this rule?
Could you give me more details about this rule?

Kind regards,
Stefania Botta.

Print this item

  Copyright
Posted by: Schmidt - 02-05-2012, 10:22 AM - Forum: MISRA-C:2004 Exemplar Suite - Replies (1)

Hello,
I want to use the Exemplar Suite for the validation of a static code analyzer. Is it allowed to use copies of some of the files in my validation documentation? The documentation is only for internal use.

Print this item

  MISRA controllability rationale
Posted by: Haasec - 01-05-2012, 11:43 AM - Forum: MISRA SA discussions - Replies (1)

Hello,
I found a reference on the internet yesterday that in '06 or '07 MISRA had created a technical report that helps an engineer classify controllability for ISO-26262. It also indicated that this report is free? I did look in the publications section but I didn't seem to find the technical report name that I found elsewhere on the internet. Could someone please provide some more detail on this report? I understand that the SAEJ2980 specification is in development but I can't wait for it at this time.


Regards,
Chad Haase

Print this item

  does MISRA C rule 15.0 apply to MISRA AC AGC?
Posted by: ggoulas - 27-04-2012, 10:04 AM - Forum: MISRA AC AGC discussions - Replies (1)

Hello,
The rule 15.0 that has been added in MISRA-C edition 2 as a required rule is not present in the MISRA AC AGC document.
Should it be ignored in the context of Auto Code?
If not, is it an OBL rule? a REC rule?
Regards,
G.Goulas.

Print this item

  19.13 and Assembly
Posted by: gs - 18-04-2012, 08:08 PM - Forum: 6.19 Preprocessing Directives - Replies (3)

Does the following code violate rule #19.13?

Code:
#define QWER { asm ASDF #$7F; }
In this case, "$" means "value" and "#" means "address of" and is not the pasting operator.

Print this item

  8.9 and 3rd party library code
Posted by: gs - 19-03-2012, 03:32 PM - Forum: 6.8 Declarations and Definitions - Replies (1)

Hi,
Does rule #8.9 apply to objects/functions declared in 3rd party library code?

Thanks

Print this item

  Need for Both C and C++ Guidelines?
Posted by: bmbrown - 05-03-2012, 04:10 PM - Forum: C++ General - No Replies

Do the C++ guidelines stand on their own or do the C++ guidelines assume that the C guidelines are being followed as well? Our source code is a mixture of C and C++, but it is compiled using a C++ compiler. We are trying to determine which guideline(s) we need to acquire licenses for.

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 261 online users.
» 0 Member(s) | 258 Guest(s)
Applebot, 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: 837