473,395 Members | 1,418 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,395 software developers and data experts.

commenting no-op lines lead to wrong results

hi,

I'm just having a weird problem that I can't explain by myself and
would appreciate someone else's view on this piece of code (used in a
JNI project). Basically if I remove some no-op lines the compiled
library does not produce a valid result (does not load the file). I
suspect that this can come from an error in the compile/linking chain
but can't spot it... Has anyone already face something like that ? :

void Store::load(const string& filename){
ifstream is(filename.c_str(), ios::binary | ios::in);
DataInputStream dis(&is);
Vector v;
bool test;
while(dis>>v){
addVector(v);

//no-op!!!!!!
test=false;
}
is.close();
int i=0;

//no-op!!!!!!!
cout<<dis<<" "<<i<<" "<<" "<<endl;
}

cheers

Jun 26 '06 #1
6 1530
ju****************@gmail.com wrote:
I'm just having a weird problem that I can't explain by myself and
would appreciate someone else's view on this piece of code (used in a
JNI project). Basically if I remove some no-op lines
They are not "no-op", they are "unimportant", maybe. Remember that
'cout <<' has *side effects*, and accessing a variable can affect how
CPU cache is managed (although this is not defined in the language,
of course).
the compiled
library does not produce a valid result (does not load the file). I
suspect that this can come from an error in the compile/linking chain
but can't spot it... Has anyone already face something like that ? :
Yes, plenty of examples when compiler is at fault and generates wrong
code for the program, especially if the optimizer is overly aggressive.

Try disabling optimizations and then step them up by one level and stop
when the problem shows up. Use the last optimization level on which
there was no problem.
[..]


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 26 '06 #2
ju****************@gmail.com wrote:
hi,

I'm just having a weird problem that I can't explain by myself and
would appreciate someone else's view on this piece of code (used in a
JNI project). Basically if I remove some no-op lines the compiled
library does not produce a valid result (does not load the file). I
suspect that this can come from an error in the compile/linking chain
but can't spot it... Has anyone already face something like that ? :

void Store::load(const string& filename){
ifstream is(filename.c_str(), ios::binary | ios::in);
DataInputStream dis(&is);
Vector v;
bool test;
while(dis>>v){
addVector(v);

//no-op!!!!!!
test=false;
}
is.close();
int i=0;

//no-op!!!!!!!
cout<<dis<<" "<<i<<" "<<" "<<endl;
}


Most often this will be due to a bug in your code, such as stack
corruption, which is hidden by the presence of the no-op lines. In this
case, are you sure that the Vector class is correct? And the addVector
function? What happens when you step through it with a debugger?

Of course, it could be a compiler bug, but that's much less likely.

Tom
Jun 26 '06 #3
hi,

thank you very much for your remarks, all of them very valid indeed.
I've just realised that I could have been a little bit more complete on
this case...

First of all, most of my other classes are quite simple or
autogenerated by some sort of compiler compiler (wich might itself be
buggy but quite unlikely for the class inlvoved here). I've been using
them for quite a while without much trouble.

I have a set of unit test cases that passes ok with all optimization
levels from -O0 to -O2... The problem only occurs when I linked against
a set of other objects files to produce a JNI library for a java
project.

To be more precise everything is OK if I compile all other files with
-O2 and only this file with -O0... unless I keep those *useless* lines
in wich case -O2 is fine...

I can move the lines around... but can't remove them (which let me
think that it might not be a corruption of the heap...it's also the
very first thing my library does wich mean that such a corruption would
very likely be internal to this function which would also make the unit
test fail).

It becomes tricky due to the fact that the bug only occurs when the
code is loaded in the JVM and I have yet to learn how to attach a JVM
process to gdb and trigger a breakpoint when necessary...

I could of course keep -O0 but I was coding in c++ (and even assembly)
to get the more juice my machine could give me!!!!

Anyway I'm going to test that on a different tuple os/compiler/binutils
versions... maybe it will give me some hints.

cheers
ju****************@gmail.com wrote:
hi,

I'm just having a weird problem that I can't explain by myself and
would appreciate someone else's view on this piece of code (used in a
JNI project). Basically if I remove some no-op lines the compiled
library does not produce a valid result (does not load the file). I
suspect that this can come from an error in the compile/linking chain
but can't spot it... Has anyone already face something like that ? :

void Store::load(const string& filename){
ifstream is(filename.c_str(), ios::binary | ios::in);
DataInputStream dis(&is);
Vector v;
bool test;
while(dis>>v){
addVector(v);

//no-op!!!!!!
test=false;
}
is.close();
int i=0;

//no-op!!!!!!!
cout<<dis<<" "<<i<<" "<<" "<<endl;
}

cheers


Jun 26 '06 #4
If my stack is corrupted it can only comes from within the call tree of
this function isn'it ?
or can it propagate throught bad alloc/desallocation on the top of the
stack ? ie can the stack be corrupted after the bad function have
returned ?

ju****************@gmail.com wrote:
hi,

thank you very much for your remarks, all of them very valid indeed.
I've just realised that I could have been a little bit more complete on
this case...

First of all, most of my other classes are quite simple or
autogenerated by some sort of compiler compiler (wich might itself be
buggy but quite unlikely for the class inlvoved here). I've been using
them for quite a while without much trouble.

I have a set of unit test cases that passes ok with all optimization
levels from -O0 to -O2... The problem only occurs when I linked against
a set of other objects files to produce a JNI library for a java
project.

To be more precise everything is OK if I compile all other files with
-O2 and only this file with -O0... unless I keep those *useless* lines
in wich case -O2 is fine...

I can move the lines around... but can't remove them (which let me
think that it might not be a corruption of the heap...it's also the
very first thing my library does wich mean that such a corruption would
very likely be internal to this function which would also make the unit
test fail).

It becomes tricky due to the fact that the bug only occurs when the
code is loaded in the JVM and I have yet to learn how to attach a JVM
process to gdb and trigger a breakpoint when necessary...

I could of course keep -O0 but I was coding in c++ (and even assembly)
to get the more juice my machine could give me!!!!

Anyway I'm going to test that on a different tuple os/compiler/binutils
versions... maybe it will give me some hints.

cheers
ju****************@gmail.com wrote:
hi,

I'm just having a weird problem that I can't explain by myself and
would appreciate someone else's view on this piece of code (used in a
JNI project). Basically if I remove some no-op lines the compiled
library does not produce a valid result (does not load the file). I
suspect that this can come from an error in the compile/linking chain
but can't spot it... Has anyone already face something like that ? :

void Store::load(const string& filename){
ifstream is(filename.c_str(), ios::binary | ios::in);
DataInputStream dis(&is);
Vector v;
bool test;
while(dis>>v){
addVector(v);

//no-op!!!!!!
test=false;
}
is.close();
int i=0;

//no-op!!!!!!!
cout<<dis<<" "<<i<<" "<<" "<<endl;
}

cheers


Jun 26 '06 #5
ju****************@gmail.com wrote:

//no-op!!!!!!
test=false;


This is hardly a noop. test had an indeterminate value
before this. Stupid braindamaged C++ behavior of skipping
default initialization in certian cases.
Jun 27 '06 #6
* ju****************@gmail.com:

It becomes tricky due to the fact that the bug only occurs when the
code is loaded in the JVM and I have yet to learn how to attach a JVM
process to gdb and trigger a breakpoint when necessary...


That's a likely culprit then. You have static type checking all the way
up to the JVM interface, a discontinuity right there with no type
checking whatsoever, and dynamic type checking above that (in Java).
Guess where you might have used incorrect types or number of args?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jun 27 '06 #7

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

Similar topics

46
by: Profetas | last post by:
Hi, I know that this is off topic. but I didn't know where to post. Do you comment your source code while coding or after coding. for example: you write a procedure and after it is...
4
by: Ron McNulty | last post by:
Often when testing an app, I want to temporarily comment out sections of the App.config file. Is there any way to do this? Regards Ron
5
by: Anders Borum | last post by:
Hello! I was wondering if there are any guidelines to documenting our C# code? I'm not talking about the actual syntax for the Xml markup we add to the classes, methods etc., but general...
3
by: Naveen Mukkelli | last post by:
Hi All, I'm trying to create XML commenting for my code using XML commenting feature for the first time. I'm using VS.NET 2003 and C#. I'v tried the following way. Step 1: set the file name...
9
by: | last post by:
Does C++/CLI have XML style commenting like C#?? If i do /// I dont get the completion like C#
18
by: Marian F. | last post by:
The 12 years old genius function to count english words in a sentence: ' This is my function to count english words in your string ' s is the string with your words to be counted ' Returns an...
8
by: lallous | last post by:
Hello I've been programming for a number of years, however my commenting style is always different. Sometimes I use something like: /************************ * method .... * comments......
2
by: RYoung | last post by:
Can someone point me to a reference concerning source code commenting with VB 2005, ala C# commenting? I googled and found alot of links to add-ins and commercial products, but I can't find any...
1
by: Wijaya Edward | last post by:
Hi all, I have the following code: import sys import re ham_count = 0 spam_count = 0
100
by: Angel Tsankov | last post by:
Can someone recommend a good source of C/C++ coding style. Specifically, I am interested in commenting style and in particular how to indent comments and the commented code, rather than when to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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...
0
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...

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.