我想要在C语言中寻找与这个C++宏相当的东西(不一定是宏,也可以是函数)。
以下是使用C++伪代码演示该代码如何工作,实际上可能会用到该宏进行编译,但是该宏在C语言中无法使用。无法在C语言中使用模板。
我没有完全理解它的工作方式,它是否像模数
对于C语言,它的声明方式如下:
使用这个
以下是使用C++伪代码演示该代码如何工作,实际上可能会用到该宏进行编译,但是该宏在C语言中无法使用。无法在C语言中使用模板。
我没有完全理解它的工作方式,它是否像模数
%
一样工作? int v47; // ecx@78
bool v48; // sf@78
unsigned char v49; // of@78
int v79; // [sp+18h] [bp-5438h]@68
v47 = *(unsigned int *)(v2 + 65292);
v49 = __OFSUB__(v79 + 1, v47);
v48 = v79++ + 1 - v47 < 0;
char *playerra; // [sp+24h] [bp-6D0h]@20
int v26; // esi@32
unsigned __int8 v28; // of@32
v28 = __OFSUB__(playerra + 1, v26);
v27 = (signed int)&(playerra++)[-v26 + 1] < 0;
bool v10; // sf@24
unsigned __int8 v11; // of@24
int v54; // [sp+14h] [bp-508h]@19
v11 = __OFSUB__(v54 + 1, 40);
v10 = v54++ - 39 < 0;
对于C语言,它的声明方式如下:
// For C, we just provide macros, they are not quite correct.
#define __OFSUB__(x, y) invalid_operation // Generate overflow flag for (x-y)
这是宏的定义方式。
// overflow flag of subtraction (x-y)
template<class T, class U> int8 __OFSUB__(T x, U y)
{
if ( sizeof(T) < sizeof(U) )
{
U x2 = x;
int8 sx = __SETS__(x2);
return (sx ^ __SETS__(y)) & (sx ^ __SETS__(x2-y));
}
else
{
T y2 = y;
int8 sx = __SETS__(x);
return (sx ^ __SETS__(y2)) & (sx ^ __SETS__(x-y2));
}
}
使用这个
// sign flag
template<class T> int8 __SETS__(T x)
{
if ( sizeof(T) == 1 )
return int8(x) < 0;
if ( sizeof(T) == 2 )
return int16(x) < 0;
if ( sizeof(T) == 4 )
return int32(x) < 0;
return int64(x) < 0;
}
并且它使用了这个
typedef char int8;
typedef signed char sint8;
typedef unsigned char uint8;
typedef short int16;
typedef signed short sint16;
typedef unsigned short uint16;
typedef int int32;
typedef signed int sint32;
typedef unsigned int uint32;
typedef __int64 int64;
typedef __int64 sint64;
typedef unsigned __int64 uint64;
int
,因此甚至可以删除__OFSUB__的上半部分。 - Till