system("pause")为什么会影响到变量?
程序很长,只能贴一段出来:
int64_t *VName = 0;
//system("pause");
int acLen = 0;
VName = decodeOID(str+lennlen+1,parseVB.var_name_length,&acLen);
printf("\tObject Identifier: 1.3.");
int loop_val;
VName++;
for(loop_val = 0+1;loop_val<acLen;loop_val++)
{
printf("%d.",*VName++);
}
printf("\n");
就是注释的那句系统调用。当注释掉它的时候,decodeOID函数就只能算出错误的结果,恢复它就能算出正确结果。编译环境是XP下用gcc。
decodeOID()函数如下:
int64_t* decodeOID(char *val, int length, int *antualLength)
{
int temp;
int64_t temp64;
int64_t *reval, *originalReVal;
char *tempseg, *originalTemSeg;
if((reval = malloc(sizeof(int64_t)*length)) == NULL)
{ fprintf(stderr,"Cannot allocate space for reval\n");
system("pause");
exit(1);
}
if((tempseg = malloc(sizeof(char)*10)) == NULL)
{ fprintf(stderr,"Cannot allocate space for tempseg\n");
system("pause");
exit(1);
}
originalReVal = reval;
originalTemSeg = tempseg;
*antualLength = 0;
for(;length>0;length--)
{
temp = *val++;
(*antualLength)++;
if((temp & 0x80) != 0)
{
*tempseg++ = temp;
for(;(*val & 0x80) != 0 ;)
*tempseg++ = *val++;
*tempseg++ = *val++;
for(;originalTemSeg != tempseg;)
{ temp64 *= 128;
temp64 += (*originalTemSeg++)&0x7f;
length--;
}
*reval++ = temp64;
}
else *reval++ = temp;
}
reval = originalReVal;
return reval;
}
另外我发现好像不是系统调用会产生影响,我把那里写成printf("Kaka");之类的东西也会得到奇怪的结果。是不是VName的初始化有问题?