为了方便大家,我再把我的测试程序和关键字表贴出来,我写的是一个pascal语言的子集--simple语言,大连理工的编译上面的。关键字表KeyWord.datand array begin bool call case char constant do else end false for if input integer not of or output procedure program read real repeat set then to true until var while write
测试程序rfile.pasprogram prochar (input,output); /*chu li zi fu */ var ordch:integer; ch,predch,succch:char; begin /*input words read(ch); writeln('ch=',ch); /*count the ID*/ ordch:=ord(ch); predch:=pred(ch); succch:=succ(ch); 324344.656 /*output*/ writelin('ordch=',ordch,'predch=',predch,'succch=',succch); end
那你在用到lookup返回值的地方,可能就得到一个不确定的数字。这会引起不少问题,特别是release版。这样的编程习惯不好。建议你看看如The Prictice of Programming(程序设计实践), code complete, writing solid code, 等书
错误处理测试文件。efile.pas 23434.324.434 prog@#ram p23443prochar (input,output); /*chu li zi fu var ordch: integer ; ch,predch,succch: char; begin /*input words*/ read(ch); writeln('ch=,ch); /*count the ID ordch:=ord(ch); predch:=pred(ch); succch:=succ(ch); 2344234234 dfklggfgd 324344.656 /*output*/ writelin('ordch=',ordch,'predch=',predch,'succch=',succch); end
我找到了,是后面那几个free()造成的,我正在定位
找到了,是在___sbh_free_block里面的错误,这个是什么函数啊?????????
0x004039fb指令引用0x00000004内存,该内存不能引用!!!! 004039FB test bl,2 004039FE je __output+642h (00403a0b)很明显,没有引用内存啊
请你详细说明问题,我的分析如下:
1、两者使用的dll等文件是不同的。有可能是release要的dll不存在或不能正常工作(和别人的dll有冲突等)
2、dump,TRACE,等是debug专用的
3、你自己的代码中用到了#ifdef _DEBUG等似定意,便得release和degug版本不同。
这种情况我发生过多次。
4、degug运行速度比release速度慢,如果程序中用到了和运行时间有关的多进程等相关问题会发生这种情况。
再次请你详细说明问题
所以dll不兼容的可能性最大
#include <stdlib.h>
#include <io.h>
#include "accidence.h"extern Token token_String[4096];
extern pSymbol SymbolList[4096];static char *p_KeyWord[255];
static char c_Temp[255];
static int row=0,col=0;
static FILE *fp_Error;main(int argc,char *argv[])
{
FILE *fp_Program,*fp_KeyWord,*fp_Token,*fp_SymbolList; int i=0;
for(i=0;i<4096;i++)
{
SymbolList[i]=NULL;
}
for(i=0;i<255;i++)
{
p_KeyWord[i]=NULL;
}
/* if (argc!=2)
{
printf("you forgot to type your programe name \n");
exit(0);
}
if(!(fp_Program=fopen(argv[1],"r")))
{
printf("Can't open file %s!",argv[1]);
exit(1);
}*/
if(!(fp_Program=fopen("rfile.pas","r")))
{
printf("Can't open file rfile.pas!");
exit(1);
}
if(!(fp_KeyWord=fopen("KeyWord.dat","rb")))
{
printf("Can't open file KeyWord.dat!");
exit(1);
}
if(!(fp_Error=fopen("error.txt","w+")))
{
printf("Can't open file error.txt!");
exit(1);
}
for(i=0;!feof(fp_KeyWord);i++)
{
if(!(p_KeyWord[i]=(char*)malloc(20*sizeof(char))))
{
printf("Allocation momory fail!!");
exit(1);
}
fscanf(fp_KeyWord,"%s",p_KeyWord[i]);
}
free(p_KeyWord[i-1]);
p_KeyWord[i-1]=NULL; while(!feof(fp_Program))
{
for(i=0;;i++)
{
c_Temp[i]=fgetc(fp_Program);
if(c_Temp[i]=='\n')
break;
if(c_Temp[i]==EOF)
{
c_Temp[i]='\n';
break;
}
}
row++;
scanner(c_Temp);
}
fp_Token=fopen("token.txt","w+");
fp_SymbolList=fopen("symbol.txt","w+");
i=0;
while(token_String[i].Kin_Cod)
{
if(token_String[i].Kin_Cod<=37 && token_String[i].Kin_Cod>=34)
{
if(SymbolList[token_String[i].Index]->Type==IND||
SymbolList[token_String[i].Index]->Type==STRING)
fprintf(fp_Token,"(%d,'%s')",token_String[i].Kin_Cod,
SymbolList[token_String[i].Index]->Addr);
if(SymbolList[token_String[i].Index]->Type==INT)
fprintf(fp_Token,"(%d,%d)",token_String[i].Kin_Cod,
SymbolList[token_String[i].Index]->lVal);
if(SymbolList[token_String[i].Index]->Type==FLOAT)
fprintf(fp_Token,"(%d,%f)",token_String[i].Kin_Cod,
SymbolList[token_String[i].Index]->dVal);
}
else
fprintf(fp_Token,"(%d,_)",token_String[i].Kin_Cod);
fprintf(fp_Token,"\n");
i++;
}
i=0;
while(SymbolList[i])
{
if(SymbolList[i]->Type==IND)
fprintf(fp_SymbolList,"%s, IND\n",SymbolList[i]->Addr);
if(SymbolList[i]->Type==INT)
fprintf(fp_SymbolList,"%ld, INT\n",SymbolList[i]->lVal);
if(SymbolList[i]->Type==FLOAT)
fprintf(fp_SymbolList,"%f, FLOAT\n",SymbolList[i]->dVal);
if(SymbolList[i]->Type==STRING)
fprintf(fp_SymbolList,"%s, STRING\n",SymbolList[i]->Addr);
i++;
}
for(i=0;SymbolList[i];i++)
free(SymbolList[i]);
for(i=0;p_KeyWord[i];i++)
free(p_KeyWord[i]);
fclose(fp_Token);
fclose(fp_SymbolList);
fclose(fp_Program);
fclose(fp_KeyWord);
fclose(fp_Error);
system("edit token.txt");
system("edit symbol.txt");
system("edit error.txt");
}
#ifndef ACCIDENCE_H_
#define ACCIDENCE_H_#include <stdio.h>
#include <string.h>
#include <ctype.h>enum TYPE
{
IND,
INT,
FLOAT,
STRING,
NUL
};typedef struct{
unsigned int Kin_Cod;
int Index;
} Token,*pToken;typedef struct{
struct Name
{
int Head;
int Tail;
};
enum TYPE Type;
// unsigned int Kind;
union
{
long lVal;
double dVal;
};
char * Addr;
} Symbol,*pSymbol;extern char *p_KeyWord[255];
extern char c_Temp[255];
extern int row,col;
extern FILE *fp_Error;static Token token_String[4096];
static pSymbol SymbolList[4096];
static int tok_Curr=0,sym_Curr=0;
printerr();
int lookup(char *String,enum TYPE type);identifier(char Line[])
{
int i=0;
int flag=0;
char Temp[255];
while(Line[col]==' ')
{
col++;
}
for(i=0;isalnum(Line[col]);i++,col++)
Temp[i]=Line[col];
Temp[i]='\0';
for(i=1,flag=0;p_KeyWord[i]!=NULL;i++)
{
if(strncmp(Temp,p_KeyWord[i],255)==0)
{
token_String[tok_Curr].Kin_Cod=i+1;
token_String[tok_Curr].Index=0;
tok_Curr++;
flag=1;
break;
}
}
if(flag==0)
{
token_String[tok_Curr].Kin_Cod=34;
token_String[tok_Curr].Index=lookup(Temp,IND);
tok_Curr++;
}
while(Line[col]==' ')
{
col++;
}
}re(char Line[])
{
char *Addr=NULL;
while(Line[col]==' ')
{
col++;
}
if(Line[col+1]!='*')
{
token_String[tok_Curr].Kin_Cod=48;
token_String[tok_Curr].Index=0;
tok_Curr++;
col++;
}
else
{
token_String[tok_Curr].Kin_Cod=-1;
if(Addr=strstr(&Line[col+2],"*/"))
{
col+=(Addr-&Line[col]+2);
token_String[tok_Curr].Kin_Cod=0;
}
else
{
printerr(2);
fprintf(fp_Error,"The re in this line is not matching !\n");
token_String[tok_Curr].Kin_Cod=0;
col=strlen(Line)-1;
}
}
while(Line[col]==' ')
{
col++;
}
}const_data(char Line[])
{
token_String[tok_Curr].Index=lookup(&Line[col],NUL);
tok_Curr++;
}const_string(char Line[])
{
char *Addr=NULL;
char Temp[255];
while(Line[col]==' ')
{
col++;
}
if(Addr=strstr(&Line[col+1],"'"))
{
strncpy(Temp,&Line[col+1],Addr-1-&Line[col]);
Temp[Addr-1-&Line[col]]='\0';
token_String[tok_Curr].Kin_Cod=37;
token_String[tok_Curr].Index=lookup(Temp,STRING);
tok_Curr++;
col+=(Addr-&Line[col]+1);
}
else
{
printerr(3);
fprintf(fp_Error,"The quotation in this line is not matching !\n");
col=strlen(Line)-1;
}
while(Line[col]==' ')
{
col++;
}
}del_code(char Line[])
{
while(Line[col]==' ')
{
col++;
}
switch (Line[col])
{
case '(':token_String[tok_Curr].Kin_Cod=39;
token_String[tok_Curr].Index=0;
tok_Curr++;
col++;
break;
case ')':token_String[tok_Curr].Kin_Cod=40;
token_String[tok_Curr].Index=0;
tok_Curr++;
col++;
break;
case '*':token_String[tok_Curr].Kin_Cod=41;
token_String[tok_Curr].Index=0;
tok_Curr++;
col++;
break;
case '+':token_String[tok_Curr].Kin_Cod=43;
token_String[tok_Curr].Index=0;
tok_Curr++;
col++;
break;
case ',':token_String[tok_Curr].Kin_Cod=44;
token_String[tok_Curr].Index=0;
tok_Curr++;
col++;
break;
case '-':token_String[tok_Curr].Kin_Cod=45;
token_String[tok_Curr].Index=0;
tok_Curr++;
col++;
break;
case 92: token_String[tok_Curr].Kin_Cod=46;
token_String[tok_Curr].Index=0;
tok_Curr++;
col++;
break;
case '/':token_String[tok_Curr].Kin_Cod=48;
token_String[tok_Curr].Index=0;
tok_Curr++;
col++;
break;
case ':':
if(Line[col+1]=='=')
{
token_String[tok_Curr].Kin_Cod=51;
token_String[tok_Curr].Index=0;
col+=2;
tok_Curr++;
}
else
{
token_String[tok_Curr].Kin_Cod=50;
token_String[tok_Curr].Index=0;
col++;
tok_Curr++;
}
break;
case '<':
if(Line[col+1]=='=')
{
token_String[tok_Curr].Kin_Cod=54;
token_String[tok_Curr].Index=0;
col+=2;
tok_Curr++;
}
else if(Line[col+1]=='>')
{
token_String[tok_Curr].Kin_Cod=55;
token_String[tok_Curr].Index=0;
col+=2;
tok_Curr++;
}
else
{
token_String[tok_Curr].Kin_Cod=53;
token_String[tok_Curr].Index=0;
col++;
tok_Curr++;
}
break;
case '=':
token_String[tok_Curr].Kin_Cod=56;
token_String[tok_Curr].Index=0;
col++;
tok_Curr++;
break;
case '>':
if(Line[col+1]=='=')
{
token_String[tok_Curr].Kin_Cod=58;
token_String[tok_Curr].Index=0;
col+=2;
tok_Curr++;
}
else
{
token_String[tok_Curr].Kin_Cod=57;
token_String[tok_Curr].Index=0;
col++;
tok_Curr++;
}
break;
case '[':
token_String[tok_Curr].Kin_Cod=59;
token_String[tok_Curr].Index=0;
col++;
tok_Curr++;
break;
case ']':
token_String[tok_Curr].Kin_Cod=60;
token_String[tok_Curr].Index=0;
col++;
tok_Curr++;
break;
case ';':
token_String[tok_Curr].Kin_Cod=61;
token_String[tok_Curr].Index=0;
col++;
tok_Curr++;
break;
case 13:
break;
case 10:
break;
default:
printerr(1);
fprintf(fp_Error,"There have a illegal word '%c'.I have skip it now!\n",Line[col]);
col++;
}
while(Line[col]==' ')
{
col++;
}
}printerr(int id)
{
fprintf(fp_Error,"Lin=%d,Col=%d Error(%d) :",row,col,id);
}int lookup(char *String,enum TYPE type)
{
int i=0;
char *end=NULL;
long lTemp=0;
double dTemp=0;
if(isalpha(String[0]))
{
i=0;
while(SymbolList[i])
{
if(SymbolList[i]->Type==IND&&!strncmp(String,SymbolList[i]->Addr,255))
return i;
i++;
}
SymbolList[sym_Curr]=malloc(sizeof(Symbol));
SymbolList[sym_Curr]->Type=type;
SymbolList[sym_Curr]->Addr=malloc(sizeof(String[0])*
strlen(String));
strcpy(SymbolList[sym_Curr]->Addr,String);
return sym_Curr++;
}
if(isdigit(String[0]))
{
if(!strstr(String,"."))
{
lTemp=strtol(String,&end,10);
col+=(end-&String[0]);
i=0;
while(SymbolList[i])
{
if(lTemp==SymbolList[i]->lVal&&
SymbolList[i]->Type==INT)
return i;
i++;
}
SymbolList[sym_Curr]=malloc(sizeof(Symbol));
SymbolList[sym_Curr]->lVal=lTemp;
SymbolList[sym_Curr]->Type=INT;
token_String[tok_Curr].Kin_Cod=35;
return sym_Curr++;
}
else
{
dTemp=strtod(String,&end);
col+=(end-&String[0]);
i=0;
while(SymbolList[i])
{
if(dTemp==SymbolList[i]->dVal&&
SymbolList[i]->Type==FLOAT)
return i;
i++;
}
SymbolList[sym_Curr]=malloc(sizeof(Symbol));
SymbolList[sym_Curr]->dVal=dTemp;
SymbolList[sym_Curr]->Type=FLOAT;
token_String[tok_Curr].Kin_Cod=36;
return sym_Curr++;
}
}
}scanner(char Line[])
{
col=0;
while(Line[col]!=13&&Line[col]!=10)
{
while(Line[col]==' ')
col++;
if(isalpha(Line[col]))
identifier(Line);
while(Line[col]==' ')
col++;
if(Line[col]=='/')
re(Line);
while(Line[col]==' ')
col++;
if(isdigit(Line[col]))
const_data(Line);
while(Line[col]==' ')
col++;
if(Line[col]==39)
const_string(Line);
while(Line[col]==' ')
col++;
if(!isalpha(Line[col])||Line[col]==' ')
del_code(Line);
while(Line[col]==' ')
col++;
}
col=0;
}#endif //ACCIDENCE_H_
你把你的程序放到别人操作系统上进行吧
windows或NT
仔细查看自己的内存操作部分吧.
作 者:sdsuper
所属论坛:Visual C++
问题点数:10
回复次数:3
发表时间:2001-10-9 11:21:45
为什么我的程序在nt下编译通过,而在2000下不行呢?望高手说个明白!!
而且我把nt下编译好的程序在2000下执行也是会提示错误呢?
回复贴子:
回复人: nickysoft(nickysoft) (2001-10-9 11:28:33) 得0分
因为NT和2000的有些DLL文件不同,所以有时会有兼容问题
1fei(白天) 我里面用了好多c-runtime的函数,我自己无法一个一个的测试啊
我用win2k,VC6工作,没有遇到过兼容性问题,反而同样的程序在98中运行效率低下的情况倒是出现过.
涉及游戏的东西撇开不谈
另外,debug中,内存越界,程序马上会跳到异常的地方去的。查看stack可以很快找到出事的函数。并不是象你说的不报警。
你可能接触的太少了,2000不兼容我见的太多了。越兼容的东东越效率低下。
另外,他做的是控制台程序,这是ms正在放弃的程序格式。放在vc中主要是给初学者,或者测试算法用的。
我以前接触的软件公司,通常是等新的操作系统稳定后才使用新的操作系统的。因为用户大部分用的是早期的环境。
在早期的计算机及软件界大家都有个习惯,向下兼容,但自从dephi和c buidler不兼容(不同版本之间的程序不兼容,不同版本之间的vcl也不兼容)也成功的例子,ms现在很多产品都不兼容了。
vb8据说和vb7不兼容,2000和NT兼容性不好,XP更是如此。
我的意思是把debug的优化选项打上,如果没问题,执行的效率和release是相同的。
i:\prog\accidence\accidence.h(366) : warning C4715: 'lookup' : not all control paths return a value
array
begin
bool
call
case
char
constant
do
else
end
false
for
if
input
integer
not
of
or
output
procedure
program
read
real
repeat
set
then
to
true
until
var
while
write
/*chu li zi fu */
var
ordch:integer;
ch,predch,succch:char;
begin
/*input words
read(ch);
writeln('ch=',ch);
/*count the ID*/
ordch:=ord(ch);
predch:=pred(ch);
succch:=succ(ch);
324344.656
/*output*/
writelin('ordch=',ordch,'predch=',predch,'succch=',succch);
end
23434.324.434 prog@#ram p23443prochar (input,output);
/*chu li zi fu
var
ordch: integer ;
ch,predch,succch: char;
begin
/*input words*/
read(ch);
writeln('ch=,ch);
/*count the ID
ordch:=ord(ch);
predch:=pred(ch);
succch:=succ(ch);
2344234234
dfklggfgd
324344.656
/*output*/
writelin('ordch=',ordch,'predch=',predch,'succch=',succch);
end
004039FE je __output+642h (00403a0b)很明显,没有引用内存啊
004039FB mov dword ptr [edx+4],ecx
edx=0,ecx=0;这个是___sbh_free_block()函数里的,___sbh_free_block是free(),里面的,看来应该是2000的问题,谢谢各位了
而访问越界在debug版和release版的表现很可能就是你所说的:
debug看不出错误,而release非法访问.
还是多检点一下自己的程序,不要老说win2k的不好
to 1fei(白天):
对于一个不使用系统调用,只是算法描述的"正确的"程序来说,在各种操作系统下的运行应该完全一样,只要编译器符合标准.
2000不会弱到让一个正确的程序无法执行,如果提到兼容性,也应该体现在程序运行环境(涉及到API的)或者容错能力方面.而不是对一个没什么调用的算法程序有苛刻的兼容困难
to gop:
VC是一个程序包,他设计时2000还没有出来。