473,384 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,384 software developers and data experts.

bug? instruction not compiled below comment

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
13 3304

"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
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
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
"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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Hayko Riemenschneider | last post by:
Hi! I've got me an XSL tranformation stylesheet for my XML file. In the XSL file I now wish to use PHP to do some scripting. So I thought I'll use the PIs like this: ...
3
by: Trogdor | last post by:
I set up a server on an AMD 650 machine running gentoo linux. I installed Apachie 2, MySQL 4.1 and PHP 4.3.11 I use another computer on my local net (192.168.0.x) to access the server as a...
0
by: Ajay Bakhshi | last post by:
Hi, I am getting the following problem on AIX. I create a small shared library. And tried to load it in python. It core dumps with the following message: Segmentation fault (core dumped) ...
22
by: Ajay | last post by:
hi! is there an authoritative source on the performance of scripting languages such as python vs. something like java, c, c++. its for a report, so it would be awesome if i could quote some...
3
by: Phil | last post by:
Hi everybody, I am a XSLT beginner and the following problem really makes me crazy ! I have a main "contacts.xml" document which contains references to several contact data XML files. My aim...
1
by: Klaus Schneider | last post by:
Hi all! In a C library compiled with gcc there is a pointer to a function defined and called from within the library. Now I'm using that library in a C++ project and I'd like to set this...
4
by: Richard | last post by:
I have a service which is used to call differenct versions of an application depending on the database version that is being used. The service has been compiled in framework 1.1 and it needs to...
4
by: Mathias Waack | last post by:
Hi, I've embedded python into a legacy application. It works - most of the time. In some special situations the app crashes executing the "import random". There are two different situations: ...
36
by: dspfun | last post by:
Hi! Is there any way in C that one can guarantee that instructions are executed in the same order as they are written in the program? For example, say I have the following: instruction1;...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.