I have some code that compiles and runs on MSVC++ but will not compile on GCC. I have made a test snippet that follows. My goal was to move the static method from BFSMask to BFSMaskSized. Can someone explain what is going on with the errors (esp. the weird 'operator<' error)? Thank you.
In the case of both #defines are 0, then the code compiles on GCC.
#define DOESNT_COMPILE_WITH_GCC 0
#define FUNCTION_IN_PARENT 0
I get errors if I change either #define to 1. Here are the errors I see.
#define DOESNT_COMPILE_WITH_GCC 0
#define FUNCTION_IN_PARENT 1
Test.cpp: In static member function 'static typename Snapper::BFSMask<T>::T_Parent::T_SINT Snapper::BFSMask<T>::Create_NEZ(TCMP)':
Test.cpp(492): error: 'CreateMaskFromHighBitSized' was not declared in this scope
#define DOESNT_COMPILE_WITH_GCC 1
#define FUNCTION_IN_PARENT 0
Test.cpp: In static member function 'static typename Snapper::BFSMask<T>::T_Parent::T_SINT Snapper::BFSMask<T>::Create_NEZ(TCMP) [with TCMP = int, T = int]':
Test.cpp(500): instantiated from 'TVAL Snapper::BFWrappedInc(TVAL, TVAL, TVAL) [with TVAL = int]'
Test.cpp(508): instantiated from here
Test.cpp(490): error: invalid operands of types '<unresolved overloaded function type>' and 'unsigned int' to binary 'operator<'
#define DOESNT_COMPILE_WITH_GCC 1
#define FUNCTION_IN_PARENT 1
Test.cpp: In static member function 'static typename Snapper::BFSMask<T>::T_Parent::T_SINT Snapper::BFSMask<T>::Create_NEZ(TCMP) [with TCMP = int, T = int]':
Test.cpp(500): instantiated from 'TVAL Snapper::BFWrappedInc(TVAL, TVAL, TVAL) [with TVAL = int]'
Test.cpp(508): instantiated from here
Test.cpp(490): error: invalid operands of types '<unresolved overloaded function type>' and 'unsigned int' to binary 'operator<'
Here is the code
namespace Snapper
{
#define DOESNT_COMPILE_WITH_GCC 0
#define FUNCTION_IN_PARENT 0
// MASK TYPES
// NEZ - Not Equal to Zero
#define BFSMASK_NEZ(A) ( ( A ) | ( 0 - A ) )
#define BFSELECT_MASK(MASK,VTRUE,VFALSE) ( ((MASK)&(VTRUE)) | ((~(MASK))&(VFALSE)) )
template<typename TVAL> TVAL BFSelect_MASK(TVAL MASK,TVAL VTRUE,TVAL VFALSE)
{ return(BFSELECT_MASK(MASK,VTRUE,VFALSE)); }
//-----------------------------------------------------------------------------
// Branch Free Helpers
template<int BYTESIZE> struct BFSMaskBase {};
template<> struct BFSMaskBase<2>
{
typedef UINT16 T_UINT;
typedef SINT16 T_SINT;
};
template<> struct BFSMaskBase<4>
{
typedef UINT32 T_UINT;
typedef SINT32 T_SINT;
};
template<int BYTESIZE> struct BFSMaskSized : public BFSMaskBase<BYTESIZE>
{
static const int SizeBytes = BYTESIZE;
static const int SizeBits = SizeBytes*8;
static const int MaskShift = SizeBits-1;
typedef typename BFSMaskBase<BYTESIZE>::T_UINT T_UINT;
typedef typename BFSMaskBase<BYTESIZE>::T_SINT T_SINT;
#if FUNCTION_IN_PARENT
template<int N> static T_SINT CreateMaskFromHighBitSized(typename BFSMaskBase<N>::T_SINT inmask);
#endif
};
template<typename T> struct BFSMask : public BFSMaskSized<sizeof(T)>
{
// BFSMask = -1 (all bits set)
typedef BFSMask<T> T_This;
// "Import" the Parent Class
typedef BFSMaskSized<sizeof(T)> T_Parent;
typedef typename T_Parent::T_SINT T_SINT;
#if FUNCTION_IN_PARENT
typedef T_Parent T_MaskGen;
#else
typedef T_This T_MaskGen;
template<int N> static T_SINT CreateMaskFromHighBitSized(typename BFSMaskSized<N>::T_SINT inmask);
#endif
template<typename TCMP> static T_SINT Create_NEZ(TCMP A)
{
//ReDefineType(const typename BFSMask<TCMP>::T_SINT,SA,A);
//const typename BFSMask<TCMP>::T_SINT cmpmask = BFSMASK_NEZ(SA);
const typename BFSMask<TCMP>::T_SINT cmpmask = BFSMASK_NEZ(A);
#if DOESNT_COMPILE_WITH_GCC
return(T_MaskGen::CreateMaskFromHighBitSized<sizeof(TCMP)>(cmpmask));
#else
return(CreateMaskFromHighBitSized<sizeof(TCMP)>(cmpmask));
#endif
}
};
template<typename TVAL> TVAL BFWrappedInc(TVAL x,TVAL minval,TVAL maxval)
{
const TVAL diff = maxval-x;
const TVAL mask = BFSMask<TVAL>::Create_NEZ(diff);
const TVAL incx = x + 1;
return(BFSelect_MASK(mask,incx,minval));
}
SINT32 currentsnap = 0;
SINT32 SetSnapshot()
{
currentsnap=BFWrappedInc<SINT32>(currentsnap,0,20);
return(currentsnap);
}
}