473,503 Members | 8,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strange problem with optimisation

G'day

I have encountered quite a strange problem with a new function i've added
to an existing software.

Pseudo code of actions.

-- begins --

func_foo (){

/* already in software */

while (packet) {
/* call to my function */
func_bar();
}
}

/* my function */
void func_bar () {
/*some static variables*/

/*and declaring an instance of a structure (defined previously containing
3 double) */
roundTripTime rtt;

/*rtt being initialised*/
init_rtt(&rtt);

/* function that does the processing, internally calls many other
functions */
func_baz(&rtt);

#ifdef DEBUG
printf_rtt(&rtt);
#endif

/*Not a part of the code.. .*/
/*sleep(1)i*/
fprintf (fp, "%f,%f,%f\n",rtt.t_half,rtt.t_otherhalf,rtt.t_tota l);
return;
}

-- ends --

Now ideally the last f-print should print to file the value stored in
rtt.elements. And each time new values should be evaluated and printed
to file.

-- the problem --
What actually happens is, each time only initialised values of rtt.elements
is printed to screen, not the computed or derived values. Strangely though,
if I introduce a 'sleep' or 'getchar' command before or just after the
'fprintf', appropriate values (computed values) are printed out.

I get the impression, the compiler (gcc-2.95) is playing tricks here in
trying to optimise code. I am not using any -O flags.
Has anyone ecountered a similar issue?
Any input greatly appreciated.

thanks
-r
PS: . no threads used in this software
. compiler gcc-2.95
. if the question isnt appropriate for this newsgroup, please let me
know.
Nov 14 '05 #1
1 1316
Mac
On Wed, 27 Oct 2004 12:09:27 +1000, Rahul Iyer wrote:
G'day

I have encountered quite a strange problem with a new function i've
added to an existing software.

Pseudo code of actions.

-- begins --

func_foo (){

/* already in software */

while (packet) {
/* call to my function */
func_bar();
}
}

/* my function */
void func_bar () {
/*some static variables*/

/*and declaring an instance of a structure (defined previously
containing
3 double) */
roundTripTime rtt;

/*rtt being initialised*/
init_rtt(&rtt);

/* function that does the processing, internally calls many other
functions */
func_baz(&rtt);

#ifdef DEBUG
printf_rtt(&rtt);
#endif

/*Not a part of the code.. .*/
/*sleep(1)i*/
fprintf (fp, "%f,%f,%f\n",rtt.t_half,rtt.t_otherhalf,rtt.t_tota l);
return;
}

-- ends --

Now ideally the last f-print should print to file the value stored in
rtt.elements. And each time new values should be evaluated and printed
to file.

-- the problem --
What actually happens is, each time only initialised values of
rtt.elements is printed to screen, not the computed or derived values.
Strangely though, if I introduce a 'sleep' or 'getchar' command before
or just after the 'fprintf', appropriate values (computed values) are
printed out.

I get the impression, the compiler (gcc-2.95) is playing tricks here in
trying to optimise code. I am not using any -O flags. Has anyone
ecountered a similar issue? Any input greatly appreciated.

thanks
-r
PS: . no threads used in this software
. compiler gcc-2.95
. if the question isnt appropriate for this newsgroup, please let me
know.


Compiler specific questions are off-topic here.

here is a URL for the FAQ list:
http://docs.mandragor.org/files/Prog...C-faq/top.html

Also see the "Welcome to comp.lang.c!" post which periodically appears
in this newsgroup.

If your standard library does have a bug, I imagine you are not the first
person to discover it. You may want to search on a platform specific
mailing list or something.

And you can try to find a platform specific group, too.

Or, if you think the bug just might be in your code (it probably is) then
you can try to whittle the code down to the smallest example which shows
the problem and post it here, in its entirety so that people can cut and
paste it onto their own machines and run it through their favorite
compilers or source checkers or whatever.

If the code is totally platform specific, you probably shouldn't post it
here no matter how small you make it.

--Mac

Nov 14 '05 #2

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

Similar topics

6
1692
by: KefX | last post by:
Hi guys! I'm still a bit of a Python newbie, but regardless I decided to embed Python into a plugin for a freeware (closed-source) Windows music program called Jeskola Buzz. (Man, I can't believe...
43
13210
by: Patrick Laurent | last post by:
Hello I have a program with many many inlined template functions It is essential for the execution speed that every (or almost every) function marked as inlined, becomes really inlined by the...
16
1464
by: simonwittber | last post by:
Hello People. I've have a very tight inner loop (in a game app, so every millisecond counts) which I have optimised below: def loop(self): self_pool = self.pool self_call_exit_funcs =...
4
1282
by: alkee.na | last post by:
Hey, Here's a sample code you can easily guess the result. <result 1> #include <iostream> using namespace std; class AA { public: AA() { cout<<"AA();"<<endl; }
1
1980
by: David Welch | last post by:
Hi, I have a bit of code where I am relying on empty base member optimisation. The bit of code is below: template<typename Enum> struct EncodePrefix { template<Enum e> struct Apply
23
1575
by: g.ankush1 | last post by:
#include <stdio.h> /* 1st example int a() { return 1; }
83
3852
by: Anonymous | last post by:
Came across some code summarized as follows: char const* MyClass::errToText(int err) const { switch (err) { case 0: return "No error"; case 1: return "Not enough"; case 2: return "Too...
9
2230
by: hfinster | last post by:
Hello, could somebody please shed light on the following problem with g++ (4.03 and 3.3.6 as well)? Obviously, the copy constructor is not executed, if I assign the result of a function call to...
2
1240
by: special_dragonfly | last post by:
Hello, I know this might be a little cheeky, and if it is, please say, but I need a little hand optimising some code. For the simple reason that this is 'company' code and I have no idea what I'm...
0
7070
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
7316
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...
1
6976
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
5566
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,...
1
4993
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...
0
4666
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...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
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 ...
1
729
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.