I've been getting warnings from Lint (740 at http://www.gimpel.com/html/pub/msg.txt) to the effect that it warns me not to cast a pointer to a union to a pointer to an unsigned long. I knew I was casting incompatible types so I was using a reinterpret_cast and still I got the warning which surprised me.
Example:
// bar.h
void writeDWordsToHwRegister(unsigned long* ptr, unsigned long size)
{
// write double word by double word to HW registers
...
};
// foo.cpp
#include "bar.h"
struct fooB
{
...
}
union A
{
unsigned long dword1;
struct fooB; // Each translation unit has unique content in the union
...
}
foo()
{
A a;
a = ...; // Set value of a
// Lint warning
writeDWordsToHwRegister(reinterpret_cast<unsigned long*> (&a), sizeof(A));
// My current triage, but a bad one since someone, like me, in a future refactoring
// might redefine union A to include a dword0 variable in the beginning and forget
// to change below statement.
writeDWordsToHwRegister(reinterpret_cast<unsigned long*> (&(a.dword1)), sizeof(A));
}
Leaving aside exactly why I was doing it and how to solve it in the best way (void* in interface and cast to unsigned long* in writeDWordsToHwRegister?), reading the Lint warning explained that on some machines there was a difference between pointer to char and pointer to word. Could someone explain how that difference could manifest itself and maybe give examples on some processors that shows these differences? Are we talking alignment issues?
Since its an embedded system we do use exotic and in house cores so if bad things can happen, they probably will.