Re: ill-formed reference to pointer
On Jan 30, 12:38 am, Ian Collins <ian-n...@hotmail.com> wrote:
On 01/30/11 06:03 PM, m0shbear wrote:
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
It's highly unlikely that you would have to resort to macros, unless
your compiler is very old and scummy.
and I'm getting the following error: "invalid initialization
of reference of type const unsigned char*& from expression of type
u8* ".
That's right, the types don't match.
Does the inline lowercase match the macro uppercase?
Not really, macro arguments don't have types.
code:
extern "C" {
#include<stdint.h>
}
You shouldn't have to add the extern "C" here.
typedef uint8_t u8;
typedef uint64_t u64be;
These are horrible!
I use the 'be' suffix to note that the variable is explictly big-
endian instead of native-endian. Why is that bad?
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))
Why do this?
Long symbol names become annoying to read, and reinterpret_cast is
used enough that creating a wrapper macro for it is clearer.
#define XF64(dst,src) *PTR_CAST(u64be,dst) ^= *PTR_CAST(u64be
const,src); (src) += 8
The macro I'm trying to convert into an inline function.
What I'm doing is a wordsize-optimized endian-agnostic XOR of a set of
bytes, to minimize the amount of instructions generated. And the C++
version of the C-style cast maps to reinterpret_cast.
Now why does the compiler auto-constify any non-const pointer used as
the second argument in memcpy() but refuses to do so here?
template<typename T, typename P> inline T* ptr_cast(P* p) { return
reinterpret_cast<T*>(p); }
A somewhat typesafe version of PTR_CAST.