错误?指令未编入以下评论 [英] bug? instruction not compiled below comment
问题描述
我写了一个程序,发现一行源代码
没有编译出来。我在下面简单地重写了它。
程序中的注释是big5代码文本。
---我的程序---
main(){
int i,a [8];
for(i = 0; i< 3; i ++)a [i] = 0 ;
//áקK3Q·j'M |¨¥\
a [3] = - 1;
for(i = 0; i< 4; i ++)
printf("%d",a [i]);
}
---程序结束---
输出不是0 0 0 -1因为评论结束了
和\,这使得[3] = - 1被视为评论。
我不知道这是不是一个错误?
I wrote a program, and found one line of source code
not compiled out. I rewrote it for simplicity as below.
The comment in the program is big5 code text.
--- my program ---
main(){
int i, a[8];
for (i=0;i<3;i++) a[i]=0;
// áקK3Q·j′M|¨¥\
a[3]=-1;
for (i=0;i<4;i++)
printf("%d ",a[i]);
}
--- end of my program ---
The output is not "0 0 0 -1" because the comment is ended
with "\", and this makes a[3]=-1 to be regarded as comment.
I wonder this is a bug or not?
推荐答案
" walter" <公斤** @ pchome.com.tw> schrieb im Newsbeitrag
新闻:bp ******** @ netnews.hinet.net ...
"walter" <kg**@pchome.com.tw> schrieb im Newsbeitrag
news:bp********@netnews.hinet.net...
我写了一个程序,发现一行来源代码
没有编译出来。我为了简单起见重写了它,如下所示。
程序中的注释是big5代码文本。
---我的程序---
main(){
int i,a [8];
for(i = 0; i< 3; i ++)a [i] = 0;
//áקK3Q·j'M |¨¥\
a [3] = - 1;
for(i = 0; i< 4; i ++)
printf("%d",a [i]) ;
}
---我的程序结束---
输出不是0 0 0 -1因为评论以\结束
,这使得[3] = - 1被视为评论。
我不知道这是不是一个错误?
I wrote a program, and found one line of source code
not compiled out. I rewrote it for simplicity as below.
The comment in the program is big5 code text.
--- my program ---
main(){
int i, a[8];
for (i=0;i<3;i++) a[i]=0;
// áקK3Q·j′M|¨¥\
a[3]=-1;
for (i=0;i<4;i++)
printf("%d ",a[i]);
}
--- end of my program ---
The output is not "0 0 0 -1" because the comment is ended
with "\", and this makes a[3]=-1 to be regarded as comment.
I wonder this is a bug or not?
没有错误。最后的''\'''逃脱'换行符,因此评论
不会在这里结束
Robert
No bug. the ''\'' at the end "escapes" the newline and therefore the comment
does not end here
Robert
walter< kg ** @ pchome .com.tw>写道:
walter <kg**@pchome.com.tw> wrote:
我写了一个程序,发现一行源代码没有编译出来。我简单地重写了它,如下所示。
程序中的注释是big5代码文本。
---我的程序---
#include< stdio.h> main(){
int main(void){int i,a [8];
for(i = 0; i< 3; i ++)a [i] = 0;
/ /áקK3Q·j'M |¨¥\
a [3] = - 1;
for(i = 0; i< 4; i ++)
printf(%d,a [i]);
返回0; }
---程序结束---
输出不是0 0 0 -1因为评论以\结束
,这使得[3] = - 1被视为评论。
我不知道这是不是一个错误?
I wrote a program, and found one line of source code
not compiled out. I rewrote it for simplicity as below.
The comment in the program is big5 code text.
--- my program --- #include <stdio.h> main(){ int main( void ){ int i, a[8];
for (i=0;i<3;i++) a[i]=0;
// áקK3Q·j′M|¨¥\
a[3]=-1;
for (i=0;i<4;i++)
printf("%d ",a[i]); return 0; }
--- end of my program ---
The output is not "0 0 0 -1" because the comment is ended
with "\", and this makes a[3]=-1 to be regarded as comment.
I wonder this is a bug or not?
根据标准中的定义,C预处理器需要
删除任何反斜杠后紧跟一个换行符,
因此拼接物理源线以形成逻辑源线。
这种拼接发生在标记化和注释消除之前。
因此,我认为上面的构造是你代码中的一个缺陷。
FWIW,我使用的编译器会发出警告:多行注释
诊断。
HTH
问候
-
Irrwahn
(ir*******@freenet.de)
Per definition in the standard, the C preprocessor is required to
delete any backslash immediately followed by a new-line character,
thus "splicing physical source lines to form logical source lines".
This splicing happens prior to tokenization and comment elimination.
Therefore I consider the above construct to be a flaw in your code.
FWIW, the compiler I use emits a "warning: multi-line comment"
diagnostic.
HTH
Regards
--
Irrwahn
(ir*******@freenet.de)
在消息< bp ******** @ netnews.hinet.net> ;
walter< kg ** @ pchome.com.tw>写道:
In message <bp********@netnews.hinet.net>
walter <kg**@pchome.com.tw> wrote:
---我的程序---
main(){
int i,a [8];
for(i = 0; i< 3; i ++)a [i] = 0;
//áקK3Q·j'M |¨¥\
a [3] = - 1;
for(i = 0; i< 4; i ++)
printf("%d",a [i]);
}
---我的结尾程序---
输出不是0 0 0 -1因为评论以\结束
,这使得[3] = - 1被视为评论。
我不知道这是不是一个错误?
--- my program ---
main(){
int i, a[8];
for (i=0;i<3;i++) a[i]=0;
// áקK3Q·j′M|¨¥\
a[3]=-1;
for (i=0;i<4;i++)
printf("%d ",a[i]);
}
--- end of my program ---
The output is not "0 0 0 -1" because the comment is ended
with "\", and this makes a[3]=-1 to be regarded as comment.
I wonder this is a bug or not?
我怀疑你的编译器没有被指定为处理Big5源文件。 Big5
并不是一个非常好的编码方法,正是因为这个原因 - 标准
ASCII类工具容易误解它。你可能会在字符串文字中出现更糟糕的问题。
-
Kevin Bracey,首席软件工程师
Tematic Ltd电话:+44(0)1223 503464
182-190 Newmarket Road传真:+44(0)1223 503458
剑桥,CB5 8HE,英国WWW: http://www.tematic.com/
这篇关于错误?指令未编入以下评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!