Re: strange problem with optimisation
From: Mac (foo_at_bar.net)
Date: 10/27/04
- Next message: Merrill & Michele: "Re: derangement: coding review request"
- Previous message: kimimaro: "Re: hi i am a girl who were trying a bit on C can someone help?"
- In reply to: Rahul Iyer: "strange problem with optimisation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 27 Oct 2004 04:15:32 GMT
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_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/Programming_languages/C/clc_faq_en/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
- Next message: Merrill & Michele: "Re: derangement: coding review request"
- Previous message: kimimaro: "Re: hi i am a girl who were trying a bit on C can someone help?"
- In reply to: Rahul Iyer: "strange problem with optimisation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|