__declspec(naked) int func( ... ) { __asm mov eax , [esp+4] __asm ret }
cout<< func( i ); 结果肯定一致。 [解决办法] 这个不错。。 [解决办法] 好了,纯粹C++版本来了。
int func(float a) { double x = a; return *(int*)&x ; }
template<class T> int func( T a ) { return *(int*)&a; }
#define CALL( a ) cout<< func( a ); printf("\t%d\n" , a );
struct T1 { double a; int b; };
struct T2 { int a; double b; };
struct T3 { char a; short b; };
struct T4 { short a; char b; }; int main() { char a = 0x7f; unsigned char b = 0x7f; short c = 0x7fff; unsigned short d = 0x7fff; int e = 0x7fffffff; unsigned int f = 0x7fffffff; __int64 g = 0x7fffffffffffffff; unsigned __int64 h = 0x7fffffffffffffff; float i = 123.4567; double j = 123.4567; T1 k = {123.456,0x7fffffff}; T2 l = {0x7fffffff,123.456}; T3 m = {0x7f,0x7fff}; T4 n = {0x7fff ,0x7f};
CALL( a ); CALL( b ); CALL( c ); CALL( d ); CALL( e ); CALL( f ); CALL( j ); CALL( h ); CALL( i ); CALL( j ); CALL( k ); CALL( l ); CALL( m ); CALL( n ); }