473,544 Members | 1,959 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cout problem

I have a function like this:
double MR::average_len ght_edge_on_ele ment(unsigned long element_number,
Mat_DP &element_metric , Distributed_Mes h &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;co unter_i<mesh.di m;counter_i++)
{

for (counter_j=coun ter_i+1;counter _j<mesh.dim+1;c ounter_j++)
{
average_lenght+ =MR::square_len ghtM_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 1365
Youssef Mesri wrote:
I have a function like this:
double MR::average_len ght_edge_on_ele ment(unsigned long element_number,
Mat_DP &element_metric , Distributed_Mes h &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;co unter_i<mesh.di m;counter_i++)
{

for (counter_j=coun ter_i+1;counter _j<mesh.dim+1;c ounter_j++)
{
average_lenght+ =MR::square_len ghtM_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_len ght_edge_on_ele ment(unsigned long element_number,
Mat_DP &element_metric , Distributed_Mes h &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;co unter_i<mesh.di m;counter_i++)
{

for (counter_j=coun ter_i+1;counter _j<mesh.dim+1;c ounter_j++)
{
average_lenght+ =MR::square_len ghtM_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_len ght_edge_on_ele ment(unsigned long
element_number, Mat_DP &element_metric , Distributed_Mes h &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;co unter_i<mesh.di m;counter_i++)
{

for (counter_j=coun ter_i+1;counter _j<mesh.dim+1;c ounter_j++)
{
average_lenght+ =MR::square_len ghtM_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
3488
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 header. In this basic header i must NOT include iostream. Iostereams thus get included after my basic header, at any random place
19
1501
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. The statements like this: cout<<"something\n" ; should be made as
5
6241
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 some Matlab routines in C++ for reusing them identically in Matlab and some other simulation tools. For computational algebra I want to use the Matrix...
9
2109
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 some reasons I want to implement it on my own. One goal is to make it robust against version changes and corrupted files. That means, when an object...
6
21048
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. What the code does: * First writes "This is sent to prompt" to prompt.
4
2250
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
2429
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
4833
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
2580
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 use in my program the scanf function. The program works fine, but there is one exception. When I don't insert any input, but simply press enter, I...
58
4780
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" style and what the pros and cons are (I'm using cout as example, but it really applies to any similar construct): 1) using std::cout;
0
7365
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...
0
7772
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...
0
5909
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5297
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4918
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...
0
3415
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...
0
3409
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1841
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
988
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.