473,396 Members | 2,115 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,396 software developers and data experts.

cout problem

I have a function like this:
double MR::average_lenght_edge_on_element(unsigned long element_number,
Mat_DP &element_metric, Distributed_Mesh &mesh )
with this function, I obtain two different results depending typically
to the cout stream.
there is here an extract of this function:
for (counter_i=0;counter_i<mesh.dim;counter_i++)
{

for (counter_j=counter_i+1;counter_j<mesh.dim+1;counte r_j++)
{
average_lenght+=MR::square_lenghtM_edge(id_i,id_j,
element_metric,mesh);
// cout << endl; // false result
cout << endl; //true result
}
}

with a cout I obtain the correct result but without it, I get an other
value.
how can you explain this behaviour
Thanks
Nov 29 '05 #1
4 1354
Youssef Mesri wrote:
I have a function like this:
double MR::average_lenght_edge_on_element(unsigned long element_number,
Mat_DP &element_metric, Distributed_Mesh &mesh )
with this function, I obtain two different results depending typically
to the cout stream.
there is here an extract of this function:
for (counter_i=0;counter_i<mesh.dim;counter_i++)
{

for (counter_j=counter_i+1;counter_j<mesh.dim+1;counte r_j++)
{
average_lenght+=MR::square_lenghtM_edge(id_i,id_j,
element_metric,mesh);
// cout << endl; // false result
cout << endl; //true result
}
}

with a cout I obtain the correct result but without it, I get an other
value.
how can you explain this behaviour


Too little code to know what's going on. Can you post a compilable
example of the problem.
Nov 29 '05 #2
Youssef Mesri wrote:
I have a function like this:
double MR::average_lenght_edge_on_element(unsigned long element_number,
Mat_DP &element_metric, Distributed_Mesh &mesh )
with this function, I obtain two different results depending typically
to the cout stream.
there is here an extract of this function:
for (counter_i=0;counter_i<mesh.dim;counter_i++)
{

for (counter_j=counter_i+1;counter_j<mesh.dim+1;counte r_j++)
{
average_lenght+=MR::square_lenghtM_edge(id_i,id_j,
element_metric,mesh);
// cout << endl; // false result
cout << endl; //true result
}
}

with a cout I obtain the correct result but without it, I get an other
value.
how can you explain this behaviour


I can't. Not enough information. However, you can experiment some more
to see what it depends on. Try disabling optimization when compiling only
the module containing your code. See if behaviour changes _without_ cout.
If it does, blame the compiler and keep optimization disabled.

V
Nov 29 '05 #3
Victor Bazarov wrote:
Youssef Mesri wrote:
I have a function like this:
double MR::average_lenght_edge_on_element(unsigned long
element_number, Mat_DP &element_metric, Distributed_Mesh &mesh )
with this function, I obtain two different results depending typically
to the cout stream.
there is here an extract of this function:
for (counter_i=0;counter_i<mesh.dim;counter_i++)
{

for (counter_j=counter_i+1;counter_j<mesh.dim+1;counte r_j++)
{
average_lenght+=MR::square_lenghtM_edge(id_i,id_j,
element_metric,mesh);
// cout << endl; // false result
cout << endl; //true result
}
}

with a cout I obtain the correct result but without it, I get an other
value.
how can you explain this behaviour

I can't. Not enough information. However, you can experiment some more
to see what it depends on. Try disabling optimization when compiling only
the module containing your code. See if behaviour changes _without_ cout.
If it does, blame the compiler and keep optimization disabled.

V

Thanks Vector,
when I disable optimization it works. but I dont understand why this
happened!! it's wrong !!
Nov 29 '05 #4
Youssef Mesri wrote:
Victor Bazarov wrote:
[...] Try disabling optimization when compiling
only
the module containing your code. See if behaviour changes _without_
cout.
If it does, blame the compiler and keep optimization disabled.

V
Thanks Vector,


You're welcome, Yoossef.
when I disable optimization it works. but I dont understand why this
happened!! it's wrong !!


Yes, it is. But keep in mind, though, that compilers are also simply
software written by people, who are allowed to make mistakes, just like
you and I. Optimization of generated machine code is a difficult task to
accomplish, and the code optimizer can simply stumble, and forget to make
the code write something to memory... That's what I once found in VC++
(Microsoft's compiler), for example, and once in aCC (HP's compiler).
It usually happens in a rather large module, which also probably includes
a ton of other C++ code from headers. To fix it you may not need to drop
optimization altogether, just bring it down a level or two.

Good luck!

V
Nov 29 '05 #5

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

Similar topics

8
by: Philip Lawatsch | last post by:
Hi, I'd like to get rid of all the cout stuff in my code. Following situation: Way over 2000 files, search and replace in all of them is not an option. All of the files include a basic...
19
by: qazmlp | last post by:
I hope comp.lang.c will not find the following question as a complete off-topic. I would like to remove ie.comment out the 'cout' statements during compilation(actually preprocessing) time. ...
5
by: uli | last post by:
Hi all! I'm posting to both newsgroups, because it's actually a C++ problem but could be that some of you using Matlab-&-MEX-&-C++ was struggling with the same problem. I'm trying to rewrite...
9
by: Ingo Nolden | last post by:
Hi there, I am writing c++ for some months now. I think I know the language now, but not yet all the tricky things of stl. For a kernel which is not using mfc I am writing a serialization. For...
6
by: Omid | last post by:
Hi. I have problems when I try to redirect everything that is sent to cout to a file. I have one piece of code that works and one that does not work. The only difference is which headers I use....
4
by: blackswift | last post by:
Hello,all I hava a problem that when did cout call its destructor? I used GCC compiler under linux , It compiles OK. and gives me : cons des as I haved expected.
12
by: pai | last post by:
Hi, This is a code . the output will be why is this so. Can any nody explain me this.. 4444 2222 7777 8888 aaaa *******************************
23
by: mahesh | last post by:
Hi all, I have following code that is supposed to increase the power by specified value. int main() { system("cls"); int i, exponent; double base; double new_base=0.0;
5
by: wongjoekmeu | last post by:
Dear All, I have written a small program to read in from console a user string. I wanted to be able to read in a string containing of all sorts of characters untill the user press enter. I have to...
58
by: Mark Casternoff | last post by:
I'm getting back into C++ after a long hiatus (they didn't have namespaces back then). I know this question is completely subjective, but I'd be interested in hearing which is the "better"...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
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
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...
0
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 project—planning, coding, testing,...

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.