473,569 Members | 2,751 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",rt t.t_half,rtt.t_ otherhalf,rtt.t _total);
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 1319
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",rt t.t_half,rtt.t_ otherhalf,rtt.t _total);
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
1697
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 how many people keep telling me "Extend Python instead!" when clearly I can't do that in this case. If somebody here tells me this, I will explode in...
43
13229
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 compiler. I already compiled the program with Intel Compiler (ICL) on Visual C++, and it works fine and fast. I verified that the functions are...
16
1476
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 = self.call_exit_funcs self_pool_popleft = self.pool.popleft self_pool_append = self.pool.append
4
1289
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
1990
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
1583
by: g.ankush1 | last post by:
#include <stdio.h> /* 1st example int a() { return 1; }
83
3871
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 much"; default: return "Unknown error";
9
2234
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 a (new) variable. Instead the memory location (address) of a temporary result variable from the function is used. This is my test code:
2
1244
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 allowed to release and not as the case may be I've changed anything that could give an indication of the company - if that makes any sense... for...
0
8118
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...
1
7666
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5504
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
5217
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
3651
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
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.