Re: Question



On 11 Jun 2008 21:23:46 GMT, richard@xxxxxxxxxxxxxxx (Richard Tobin) wrote:

In article <1292858.4WXqv0htDk@xxxxxxxx>, Max <invalid@xxxxxxxxxxxxxxx> wrote:

Can I ask C questions here?

I don't know. Why not give it a try and see if you're up to it?

If I compile this function

unsigned short div(unsigned short a, unsigned short b)
{
return a / b;
}

with warnings turned on, I am informed that

Warning test.c: 3 Assignment of int to unsigned short. Possible loss of precision
Warning test.c: 4 Assignment of int to unsigned short. Possible loss of precision
Warning test.c: 4 Assignment of int to unsigned short. Possible loss of precision

(line 3 is the line with the return statement, line 4
is the line with the closing brace)

(1) What does that mean, specifically, what is precision
in this context?

(2) How do I get rid of them? I tried all sorts of casts,
unsuccessfully. In a program with lots of such functions,
real problems can easily get lost, but I don't want to
disable warnings.


.



Relevant Pages

  • Re: Float comparison
    ... precision can be deduced from that stored value? ... int add ... total loss of precision. ... if you understand the nature of the calculations and the ...
    (comp.lang.c)
  • Re: Program crashes when running it outside dev environment
    ... highest warning levels, you may well get a diagnostic on code ... ', possible loss of data ... Would you add a cast there? ... Agreed it does not reomove the loss of precision. ...
    (comp.lang.c)
  • Re: convert CharArray to ByteArray
    ...   byte mask = 0xff; ... I get "Possible loss of precision. ... Found (int) required " ...
    (comp.lang.java.programmer)
  • Re: byte + byte -> int
    ... is in range for an int, but allows the line ... it thinks precision might be lost in a down-conversion. ... decimal places when converting from double to float -- that's loss of precision. ... complain about, so we're stuck with it ... ...
    (comp.lang.java.programmer)
  • Re: nrand48 source code looks weird ?
    ... unsigned short int xsubi, ... 'unsigned __int64' to 'unsigned short', possible loss of data ... Except these three lines produce a warning in visual c 6 ...
    (comp.lang.c)