result width

2005-02-24
2013-03-12
  • Jonny Bergdahl

    Jonny Bergdahl - 2005-02-24

    I have a function call that looks like this:

    ltoserwrpad((result.counter_close[i]-result.counter_open[i]) * markers[i].value, 10);

    the ltoserwpad function is declared like this:
    void ltoserwrpad (s_long n, signed char width)

    The struct variables is all u_short.

    The problem is the following:
    (0-1)*200 gives 65336, not -200.

    This indicates to me that the intermediate result of the calculation is made using s_short?

    How do I tell the compiler to widen the intermediate result to s_long in the calculation?

    Please advice!
    /jb

     
    • Maarten Brock

      Maarten Brock - 2005-02-24

      Cast one of the inner u_short's to s_long:

      (s_long)result.counter_close[i]

       

Log in to post a comment.