Reputation: 915
I have following code section:
----------header---------------------
typedef volatile struct REG_Base{
a;
b;
}REG_t
#define address (0xFFF45556)
------------------------------------
--------Source-----------------------
LOCAL REG_t *pToREG;
pToREG= (REG_t *) address;
-------------------------------------
I got on the last line the MISRA message "Cast between a pointer to volatile object and an integral type".
Any idea how to avoid this message?
Thx!
Upvotes: 0
Views: 5956
Reputation: 213721
MISRA has an advisory rule which bans casts from integers to pointers. The rationale is that they are concerned with the poorly defined behavior involved in case the integer cannot represent the pointer, or in case of misalignment.
This is one of the overly pedantic rules and it is just advisory. Most embedded systems will deviate from the rule.
That being said, your code contains some questionable things:
a
and b
declarations doesn't make any sense, are they some sort of ugly macros? Also note that MISRA requires the integer constant to be written as 0xFFF45556u
. This is not a bad idea, because 0xFFF45556
is of type unsigned int
, while for example 0x7FFFFFFF
is of type signed int. These things might lead to subtle bugs related to implicit type promotions unless you are careful.
Upvotes: 7