lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Thu, Oct 23, 2014 at 3:35 PM, Thiago L. <fakedme@gmail.com> wrote:

On 23/10/14 05:58 PM, Sean Conner wrote:
It was thus said that the Great Roberto Ierusalimschy once stated:
[...]
lstrlib.c, line 1142.  Change:
    buff[islittle ? i : size - 1 - i] = (n & MC);
To:
    buff[islittle ? i : size - 1 - i] = (char)(n & MC);
Explanation:  Prevents compiler warning about possible loss of data.
This compiler seems quite dumb :-) How can (n & 0xFF) loose data??
   Being charitable [1], *technically* you are potentially losing
information---values 128 to 255 may become -128 to -1, if chars are signed
[2].

   -spc (Or it could be an utterly stupid compiler)

[1]     Like Microsoft needs any charity

[2]     C standard leaves the signness [3] of a bare 'char' declaration up
        to the implementation---it can be either signed or unsigned.

[3]     Is that even a word?

I think signedness is a word... (don't ask me tho, idk)


Please forgive a naive for asking:

Technically speaking, if you change one lvalue's type to another one that isn't exactly equivalent, aren't you sort of "loosing data", or is there another, better term for that?

That is, 2^7 +1 is -128 for a "signed char" (or whatever) or it's 129 for an unsigned char, even though the rvalue's bits are the same...?