By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,849 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,849 IT Pros & Developers. It's quick & easy.

bug? instruction not compiled below comment

P: n/a
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;
// 避免被搜尋成功
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?

Nov 13 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a

"walter" <kg**@pchome.com.tw> schrieb im Newsbeitrag
news:bp********@netnews.hinet.net...
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;
// 避免被搜尋成功
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?


No bug. the '\' at the end "escapes" the newline and therefore the comment
does not end here
Robert
Nov 13 '05 #2

P: n/a
walter <kg**@pchome.com.tw> wrote:
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;
// 避免被搜尋成功
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?


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)
Nov 13 '05 #3

P: n/a
In message <bp********@netnews.hinet.net>
walter <kg**@pchome.com.tw> wrote:
--- my program ---
main(){
int i, a[8];
for (i=0;i<3;i++) a[i]=0;
// 避免被搜尋成功
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?


I suspect your compiler isn't specified as handling Big5 source files. Big5
is not a terribly good encoding method, for exactly this reason - standard
ASCII-type tools are liable to misinterpret it. You're likely to have even
worse problems in string literals.

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1223 503458
Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
Nov 13 '05 #4

P: n/a
"walter" <kg**@pchome.com.tw> wrote:
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.
I recommend you use UTF-8 code instead, as it does not
suffer from this problem. All non-ASCII characters are
encoded using only characters with values outside the
ASCII set, so there are no surprises with backslashes
or any other characters.

So, instead of writing: // 避免被搜尋成功
write: // 踹鋡急撠
I wonder this is a bug or not?


If your compiler specifies that it takes BIG5-encoded text
as input, then this is a bug. If the compiler specifies that
it takes ASCII or any ISO-8859 encoded text, then it is not
a bug, because there really is a backslash as the final
character in the line.

--
Simon.
Nov 13 '05 #5

P: n/a
Irrwahn Grausewitz:
walter <kg**@pchome.com.tw> wrote:

....

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?

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


I found a compile option -Wcomment, which could generate
"warning: multi-line comment" message. I've add this
option to my makefile. Thanks for your information.

Regards,

Nov 13 '05 #6

P: n/a
walter <kg**@pchome.com.tw> wrote:
Irrwahn Grausewitz:

<snip>
FWIW, the compiler I use emits a "warning: multi-line comment"
diagnostic.


I found a compile option -Wcomment, which could generate
"warning: multi-line comment" message. I've add this
option to my makefile. Thanks for your information.


<OT>
If you're using gcc you should include "-W -Wall" in the command line.
(No, -Wall on itself doesn't turn on all [generally useful] warnings.)
</OT>

Regards
--
Irrwahn
(ir*******@freenet.de)
Nov 13 '05 #7

P: n/a
walter wrote:

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;
// 避免被搜尋成功
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?


If you don't have a C99 compliant compiler, the line beginning
with // is a syntax error in the first place. C90 comments are
enclosed in /* ... */.

If you do have a C99 compiler (doubtful), the terminal '\' is
documented as splicing lines together, so that the "a[3]..." is
part of the comment line.

If you are using something with non-standard extensions, it is up
to you to understand what they are doing. c.l.c cannot help you,
simply because they are non-standard, undocumented (to us), and we
just don't understand them. Such questions are off-topic here.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #8

P: n/a
In <33********************************@4ax.com> Irrwahn Grausewitz <ir*******@freenet.de> writes:
<OT>
If you're using gcc you should include "-W -Wall" in the command line.
(No, -Wall on itself doesn't turn on all [generally useful] warnings.)
</OT>


-Wall on itself doesn't turn on all generally useful warnings, but the
right companion option for achieving this purpose is -O, not -W.

The warnings generated by -W have been excluded from -Wall precisely
because far too many people don't consider them as being generally useful.
IMHO, they're more like a source of compiler noise: far too much *correct*
C code triggers them.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #9

P: n/a
Irrwahn Grausewitz wrote:

walter <kg**@pchome.com.tw> wrote:
Irrwahn Grausewitz:

<snip>
FWIW, the compiler I use emits a "warning: multi-line comment"
diagnostic.


I found a compile option -Wcomment, which could generate
"warning: multi-line comment" message. I've add this
option to my makefile. Thanks for your information.


<OT>
If you're using gcc you should include "-W -Wall" in the command line.
(No, -Wall on itself doesn't turn on all [generally useful] warnings.)
</OT>


I routinely include -W -Wall -ansi -pedantic -Wwrite-strings. I
do this by running gcc through an alias (which is bypassed in make
files). I very rarely need to use any less restrictive options.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #10

P: n/a
CBFalconer <cb********@yahoo.com> wrote:
Irrwahn Grausewitz wrote:

<snip>
<OT>
If you're using gcc you should include "-W -Wall" in the command line.
(No, -Wall on itself doesn't turn on all [generally useful] warnings.)
</OT>


I routinely include -W -Wall -ansi -pedantic -Wwrite-strings. I
do this by running gcc through an alias (which is bypassed in make
files). I very rarely need to use any less restrictive options.


<OT>
Yup. However, Dan made a good point in recommending the -O option.
Otherwise some warnings (e.g. about using uninitialized automatic
variables) are ommitted, because generation of these warnings
requires information that is only available in optimizing mode.
</OT>

Regards
--
Irrwahn
(ir*******@freenet.de)
Nov 13 '05 #11

P: n/a
In <3F***************@yahoo.com> CBFalconer <cb********@yahoo.com> writes:
Irrwahn Grausewitz wrote:

walter <kg**@pchome.com.tw> wrote:
> Irrwahn Grausewitz:

<snip>
> > FWIW, the compiler I use emits a "warning: multi-line comment"
> > diagnostic.
>
> I found a compile option -Wcomment, which could generate
> "warning: multi-line comment" message. I've add this
> option to my makefile. Thanks for your information.


<OT>
If you're using gcc you should include "-W -Wall" in the command line.
(No, -Wall on itself doesn't turn on all [generally useful] warnings.)
</OT>


I routinely include -W -Wall -ansi -pedantic -Wwrite-strings. I
do this by running gcc through an alias (which is bypassed in make
files). I very rarely need to use any less restrictive options.


You must be a very lucky guy if you "very rarely" need to use platform
extensions, whose declarations/definitions in the standard headers are
suppressed by -ansi.

However, without -O, you'll *never* get warnings about using uninitialised
variables. But maybe you don't care about such things... ;-)

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #12

P: n/a
Dan Pop wrote:
CBFalconer <cb********@yahoo.com> writes:
Irrwahn Grausewitz wrote:
walter <kg**@pchome.com.tw> wrote:
> Irrwahn Grausewitz:
<snip>
> > FWIW, the compiler I use emits a "warning: multi-line comment"
> > diagnostic.
>
> I found a compile option -Wcomment, which could generate
> "warning: multi-line comment" message. I've add this
> option to my makefile. Thanks for your information.

<OT>
If you're using gcc you should include "-W -Wall" in the command
line. (No, -Wall on itself doesn't turn on all [generally useful]
warnings.) </OT>


I routinely include -W -Wall -ansi -pedantic -Wwrite-strings. I
do this by running gcc through an alias (which is bypassed in make
files). I very rarely need to use any less restrictive options.


You must be a very lucky guy if you "very rarely" need to use
platform extensions, whose declarations/definitions in the standard
headers are suppressed by -ansi.

However, without -O, you'll *never* get warnings about using
uninitialised variables. But maybe you don't care about such
things... ;-)


I left off my usual -O1 to avoid flaps about optimization versus
debuggers. Oh well.

At any rate, there is a strong resemblance to chickens and eggs.
My code tends to be portable because I use those options because
my code tends to be portable because ....

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #13

P: n/a
In <3F***************@yahoo.com> CBFalconer <cb********@yahoo.com> writes:
At any rate, there is a strong resemblance to chickens and eggs.
My code tends to be portable because I use those options because
my code tends to be portable because ....


More likely because it doesn't attempt to solve any real life programming
problems that aren't filters getting their input from stdin and producing
their output on stdout.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.