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.