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

Username
  

Password
  





  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

  regarding 38b and 48a
Posted by: stefania.botta - 02-03-2012, 03:26 PM - Forum: MISRA AC SLSF discussions - Replies (3)

Hi,

I have some doubt about the use in stateflow of matlab functions as min or max. The tools for autocoding haven't limitation to use in this way these matlab functions.

So, why it is wrong to use these functions in stateflow?

Thanks a lot,
Stefania Botta.

Print this item

  Casting pointers & Rule 5-2-7
Posted by: rfrutos - 28-02-2012, 01:38 PM - Forum: 6.4 Standard conversions (C++) - Replies (2)

The 5-2-7 rule says:

Quote:An object with pointer type sall not be converted to an unrelated pointer type, either directly or indirectly

and then shows some examples of casting between classes and structs, my question is if that is extensible to castings to primary types.
What I would like to do is something like:

Code:
typedef struct SC_MsgFrameToRbc
{
  uint32_t idIxl;
  uint32_t size;
  uint8_t frame[MAX_SIZE_FRAME];
} SC_MsgFrameToRbc;

SC_MsgFrameToRbc *msgReceived = NULL;
SC_MsgFrameToRbc msgSended = NULL;
char *buffer = NULL;


msgSended.idIxl = 1;
msgSended.size = 2
...

// Simulates sending message
memcpy(buffer, reinterpret_cast(&msgSended), sizeof(SC_MsgFrameToRbc)); // Compliant ??

// Message reception
msgReceived = reinterpret_cast(buffer); // Compliant ??

where the memcpy simulates other system-dependent code that implements message sending, would the two castings be compliant?

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 78 online users.
» 0 Member(s) | 74 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