Re: strange problem with optimisation

From: Mac (foo_at_bar.net)
Date: 10/27/04


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



Relevant Pages

  • Re: Another computer algebra system : smib
    ... Certainly sometimes a bug is discovered only after a program is ported to a new environment -- a bug that existed in the old environment too, but just had not been exercised. ... Spending time porting a program is ... If the code is a command line drive program, then there should be few differences between for platform A and code for platform B. If one uses portable thread libraries, then if code breaks on platform B, but not on A, I would certainly think it is worth while spending time on platform B to find the problem, as it is highly likely to be a logical error in the program. ... The fact this is new code, I would not release it with over 1600 warnings messages from the compiler. ...
    (sci.math.symbolic)
  • Re: Food for thought
    ... A bug could slip by in a compiler. ... Sun Certified Programmer for the Java 2 Platform ... Sun Certified Developer for the Java 2 Platform ...
    (comp.lang.java.programmer)
  • Re: SPARC CPU have a bug? very starange things!!!
    ... > I found about six sdivcc code in my binary. ... > Is this Bug of Compiler? ... on the platform your compiling on. ...
    (comp.unix.solaris)
  • Re: interesting use of NEXT SENTENCE vs. CONTINUE
    ... These days I don't do compiler maintenance, but I HAVE done in the past, so ... You had a chance to point out how adherence to the standard can improve ... >> compile it WITH MINOR MODIFICATIONS for a specific platform. ... > platform-specific extension to COBOL ...
    (comp.lang.cobol)
  • Re: interesting use of NEXT SENTENCE vs. CONTINUE
    ... I DID think any old compiler would be able to ... > compile it WITH MINOR MODIFICATIONS for a specific platform. ... > not going to go to the Standard to see what SHOULD work. ... If you write your COBOL code avoiding the things that are marked as ...
    (comp.lang.cobol)