type casts in KLD

From: Artis Caune (ac-lists_at_latnet.lv)
Date: 02/24/04

  • Next message: Bernd Walter: "Re: OT: tftp server"
    To: freebsd-hackers@freebsd.org
    Date: Tue, 24 Feb 2004 16:51:47 +0200
    
    

    Hi!

    I'm writting kld module, and have some weird problems
    with mixing types and casts.

    e.x.
      "if (long + u_long + u_long < 0)" don't work,
    but
    "if (long < 0 - u_long - u_long)" works fine!

    and code like this:
    "cur_rate = min_rate + \
                        (((max_rate - min_rate) * \
                        (cur_level / level / 100))) / 100)"
    where:
    cur_rate, min_rate, max_rate - u_long;
    cur_level, level - u_quad_t ;

    I cast-ed expresion:
    "cur_rate = min_rate + \
                        (((max_rate - min_rate) * \
                        ((u_long) cur_level / (u_quad_t) level / 100))) /
    (u_long) 100)"

    and it seems to be ok!

    Someone can point me to article, url where
    I can find more about complex arithmetic operations
    with different types and
    how to proper use different types in "if" statements?

    -- 
    Artis
    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
    

  • Next message: Bernd Walter: "Re: OT: tftp server"