Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Feb 2004 16:51:47 +0200
From:      Artis Caune <ac-lists@latnet.lv>
To:        freebsd-hackers@freebsd.org
Subject:   type casts in KLD
Message-ID:  <opr3vp8lducpfy5d@mail.latnet.lv>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?opr3vp8lducpfy5d>