473,672 Members | 2,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3321

"walter" <kg**@pchome.co m.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.co m.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*******@free net.de)
Nov 13 '05 #3
In message <bp********@net news.hinet.net>
walter <kg**@pchome.co m.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.co m.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.co m.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.co m.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*******@free net.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********@yah oo.com) (cb********@wor ldnet.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*******@free net.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.co m.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********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4160
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: <xsl:processing-instruction name="php"> echo $hello; </xsl:processing-instruction>
3
2208
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 client. MySQL works perfectly. I have created and queried databases with no problem. Apachie 2 appears to work with no problem. I can call up web pages in the expected maner.
0
1761
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) At other time with another shared lib I got: Illegal instruction: core dump
22
2420
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 well-known authority on this. thanks
3
2118
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 is to process the contacts in a single-pass XSLT process. That is why the "document()" function is what I need. I call the "document()" XPath function from a "for-each" instruction.
1
2371
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 function pointer to a C++ function. Do I have to set the C++ function __attribute__((cdecl)) ? Are there any other things I have to worry about? See example code below. Thanks very much, Klaus
4
2042
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 call the current version of the application (also compiled in framework 1.1) and also historic versions (compiled in framework 1.0). The application compiled in framework 1.1 loads correctly,
4
4020
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: 1. the sources compiled with gcc 4.1.2 crash with illegal instruction error: (running my application)
36
2075
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; instruction2; instruction3;
0
8423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8948
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8851
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8648
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8701
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7481
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5725
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4246
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.