0

I have below C++ code snippet which works perfectly fine:

Address = **(uint32_t **)(0x12345678);

I have a LDRA warning at the line mentioned above Use of C type cast. Can anyone please help me in type casting above instruction to C++ style?

Thanks, Kalyan

Andrew
  • 2,046
  • 1
  • 24
  • 37

1 Answers1

3

That's a reinterpret_cast

Only the following conversions can be done with reinterpret_cast, except when such conversions would cast away constness or volatility.

  1. A value of any integral or enumeration type can be converted to a pointer type. A pointer converted to an integer of sufficient size and back to the same pointer type is guaranteed to have its original value, otherwise the resulting pointer cannot be dereferenced safely (the round-trip conversion in the opposite direction is not guaranteed; the same pointer may have multiple integer representations) The null pointer constant NULL or integer zero is not guaranteed to yield the null pointer value of the target type; static_cast or implicit conversion should be used for this purpose.

So it would be

Address = **reinterpret_cast<uint32_t **>(0x12345678);
Caleth
  • 52,200
  • 2
  • 44
  • 75
  • 1
    In any case it's better to use linker, see https://stackoverflow.com/questions/4067811/how-to-place-a-variable-at-a-given-absolute-address-in-memory-with-gcc – Victor Gubin Feb 25 '20 at 11:09