vim7: signed/unsigned mismatch

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

vim7: signed/unsigned mismatch

Walter Briscoe
For some bizarre reason VC 5.0 and 6.0 complain about comparing unsigned
and signed data for equality. (Bizarre because they do not diagnose
analogous assignments.)

Recent changes introduced such a comparison:

D:\wfb\vim\bld\vim70aa\vim7\src ) vcvars60
Setting environment for using Microsoft Visual C++ 6.0 tools.
D:\wfb\vim\bld\vim70aa\vim7\src ) nmake -nologo -f make_mvc.mak  .\ObjGOd\spell.obj

        cl -c /W3 /nologo ... spell.c
spell.c
spell.c(6146) : warning C4018: '==' : signed/unsigned mismatch

D:\wfb\vim\bld\vim70aa\vim7\src )

Casting the signed side is the effect of the usual conversions.

if (strspn(line, " \t") == curwin->w_cursor.col)
might be more natural that a subtraction. However, strspn is only used
once in vim and is presumably not favoured by Bram.

The following might also be considered:
edit.c:             if ((int)(skipwhite(line) - line) !=
misc1.c:        ai_col = (colnr_T)(skipwhite(p) - p);
misc1.c:        ai_col = (colnr_T)(skipwhite(p) - p);
screen.c:           cap_col = skipwhite(line) - line;
spell.c:            capcol = skipwhite(line) - line;

Bram has the choice as always.

--- src/spell.c.0       Fri Jul  8 07:55:58 2005
+++ src/spell.c Sat Jul  9 05:51:44 2005
@@ -6143,7 +6143,8 @@
     if (curbuf->b_cap_prog != NULL)
     {
        endcol = 0;
-       if (skipwhite(line) - line == curwin->w_cursor.col)
+       /* if (strspn(line, " \t") == curwin->w_cursor.col) */
+       if ((colnr_T)(skipwhite(line) - line) == curwin->w_cursor.col)
        {
            /* At start of line, check if previous line is empty or sentence
             * ends there. */
--
Walter Briscoe
Reply | Threaded
Open this post in threaded view
|

Re: vim7: signed/unsigned mismatch

Bram Moolenaar

Walter Briscoe wrote:

> For some bizarre reason VC 5.0 and 6.0 complain about comparing unsigned
> and signed data for equality. (Bizarre because they do not diagnose
> analogous assignments.)

> spell.c(6146) : warning C4018: '==' : signed/unsigned mismatch

That was fixed in last night's snapshot.

> Casting the signed side is the effect of the usual conversions.
>
> if (strspn(line, " \t") == curwin->w_cursor.col)
> might be more natural that a subtraction. However, strspn is only used
> once in vim and is presumably not favoured by Bram.

I'm not sure all systems support strspn() and it works properly
everywhere.  Currently it's only used in Win32 specific code.  I'm a bit
careful with these things, it may take a long time before someone
detects a problem.

--
FIRST HEAD: All right! All right! We'll kill him first and then have tea and
            biscuits.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///
Reply | Threaded
Open this post in threaded view
|

Re: vim7: signed/unsigned mismatch

Walter Briscoe
In message <[hidden email]> of Sat, 9 Jul
2005 13:08:25 in , Bram Moolenaar <[hidden email]> writes

>
>Walter Briscoe wrote:
>
>> For some bizarre reason VC 5.0 and 6.0 complain about comparing unsigned
>> and signed data for equality. (Bizarre because they do not diagnose
>> analogous assignments.)
>
>> spell.c(6146) : warning C4018: '==' : signed/unsigned mismatch
>
>That was fixed in last night's snapshot.
Sorry to be so slow with my report. ;)

>
>> Casting the signed side is the effect of the usual conversions.
>>
>> if (strspn(line, " \t") == curwin->w_cursor.col)
>> might be more natural that a subtraction. However, strspn is only used
>> once in vim and is presumably not favoured by Bram.
>
>I'm not sure all systems support strspn() and it works properly
>everywhere.  Currently it's only used in Win32 specific code.  I'm a bit
>careful with these things, it may take a long time before someone
>detects a problem.

Fair enough. I know you target various K&R implementations.
It is absent from the '78 edition index.
It is in Vax C 2.3 documentation from '87.
--
Walter Briscoe