[求助]stack overflow的问题
我在delphi里调用一个vc的dll文件做运算,算一会就会出现stack overflow的问题~~是不是我定义的调用有问题啊~ 哪位来帮忙看看啊~~~
这个程序以前都是用C写的,现在要求改成delphi的,由于那个函数实在我是看不懂翻不过来,就想把它弄成dll来用,可是还出现了这个问题,这个函数是用来处理数据的,弄不出来怎么办啊。。。555.。。。
我在delphi里定义的
Function ioCode(AFloat:Double):Integer;
stdcall;far;external'mydll.dll' name 'ioCode;
调用时
test:array[0..4000000]of Single;
for i=0 to n do
num:=ioCode(test[i]);
这个i没运行到n的时候就会提示错误了。。。麻烦各位帮忙给看看啊~~ 万分感谢!
C里dll的程序
extern "C"{
_declspec(dllexport) int ioCode(float AFloat)
{
int LongInt;
int IBM_exp;
int IBM_fraction;
int TheSign;
float f=AFloat;
char * pp = (char *)(&f);
int ATemp = *((int *) (pp));
int Sun_exp = ATemp & 0x7f800000;
int Sun_fraction = ATemp & 0x7fffff;
short int AMod = Sun_exp-(IBM_exp << 2);
TheSign = (ATemp & 0x80000000)>>31;
Sun_exp = Sun_exp >>23;
if ( Sun_exp == 0 && Sun_fraction == 0 )
{
IBM_exp = 0x40;
IBM_fraction = 0;
IBM_exp +=64;
LongInt = (TheSign<<31)|(IBM_exp<<24)|IBM_fraction;
return LongInt;
}
if ( Sun_exp == 0 && Sun_fraction != 0 )
{
Sun_exp = 253;
}
Sun_exp = Sun_exp-126; // Sun_exp-127+1
IBM_fraction = Sun_fraction | 0x800000 ; // the highest bit is 1
//exponent/4
IBM_exp = Sun_exp >> 2;
AMod = Sun_exp-(IBM_exp << 2);
if ( AMod != 0 )
{
IBM_exp++;
AMod = 4-AMod;
}
IBM_fraction = IBM_fraction >> AMod;
IBM_exp +=64;
LongInt = (TheSign<<31)|(IBM_exp<<24)|IBM_fraction;
return LongInt;
}
};