472,353 Members | 1,178 Online

# 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 1303
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... 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... 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... 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... 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... 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... 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... 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... 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... 0 by: Naresh1 | last post by: What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge... 0 by: antdb | last post by: Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was... 2 by: Matthew3360 | last post by: Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it... 0 by: Arjunsri | last post by: I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and... 0 by: WisdomUfot | last post by: It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific... 0 by: Matthew3360 | last post by: Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web... 0 by: Oralloy | last post by: Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the... 0 by: BLUEPANDA | last post by: At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS... 0 by: Rahul1995seven | last post by: Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...