strange problem with optimisation

Discussion in 'C Programming' started by Rahul Iyer, Oct 27, 2004.

  1. Rahul Iyer

    Rahul Iyer Guest

    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.
     
    Rahul Iyer, Oct 27, 2004
    #1
    1. Advertising

  2. Rahul Iyer

    Mac Guest

    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
     
    Mac, Oct 27, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fredrik Ramsberg

    Optimisation of regexps in Perl?

    Fredrik Ramsberg, Oct 14, 2003, in forum: Perl
    Replies:
    2
    Views:
    482
    Fredrik Ramsberg
    Oct 15, 2003
  2. Roedy Green

    boolean loop optimisation

    Roedy Green, Sep 11, 2003, in forum: Java
    Replies:
    8
    Views:
    2,844
    Chris Uppal
    Sep 12, 2003
  3. sorry.no.email@post_NG.com

    Search Engine Optimisation

    sorry.no.email@post_NG.com, May 8, 2006, in forum: HTML
    Replies:
    0
    Views:
    360
    sorry.no.email@post_NG.com
    May 8, 2006
  4. Oliver Batchelor
    Replies:
    1
    Views:
    386
    Frank Schmitt
    Jul 22, 2003
  5. Agent Mulder

    Re: Code optimisation

    Agent Mulder, Aug 27, 2003, in forum: C++
    Replies:
    1
    Views:
    317
    Peter van Merkerk
    Aug 27, 2003
Loading...

Share This Page