Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Casting pointers & Rule 5-2-7
#1
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?
<t></t>
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)