Evtl. bekommst du auch eine Exception oder Daten von der falschen Stelle
(ARM), je nachdem wie dein Prozessor auf falsch ausgerichtete Zugriffe
reagiert (Stichwort Alignment).
Je nach Endianness kann da auch etwas anderes herauskommen.
Anders gesagt, sowas tut man nicht.
Das ist ein extrem windiges Konstrukt, das in solider Software nichts zu
suchen hat.
Besser ist
1 | data =
|
2 | ((uint32_t) ptr[index + 0]) << 0) |
|
3 | ((uint32_t) ptr[index + 1]) << 8) |
|
4 | ((uint32_t) ptr[index + 2]) << 16) |
|
5 | ((uint32_t) ptr[index + 3]) << 24);
|
schön in ein Unterprogramm verpackt.
Oder auch
1 | data =
|
2 | ((uint32_t) ptr[index + 0]) << 24) |
|
3 | ((uint32_t) ptr[index + 1]) << 16) |
|
4 | ((uint32_t) ptr[index + 2]) << 8) |
|
5 | ((uint32_t) ptr[index + 3]) << 0);
|
falls die Daten Big-Endian sind.