2010/6/9 Dominique Pellé:
> björn wrote:
>
>> $ gcc --version
>> i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5659)
>>
>> All I can say is that if you want to print an off_t value on OS X 10.6
>> then "%lld" must be used or that warning pops up.
>>
>> Since those two lines in fileio.c are the only places where an off_t
>> is printed I may just go ahead and add some MacVim-specific #ifdefs to
>> get rid of the warning in the MacVim code, unless some other solution
>> presents itself.  I might also try some Apple-specific mailing list to
>> see if I can get any answers there about this warning.
>
> How about putting a cast to long as follows?  If LONG_LONG_OFF_T
> is undefined, then casting off_t to long does not lose precision
> and should fix the compilation warning:

Thanks Dominique, that seems like a clever trick to me.  I just tried
it and it works fine (the warning goes away).

I also made a little test program to print a 64 bit int using %ld as
well as %lld and both give the same result (so this patch works
properly).

I modified the patch slightly by moving the final parenthesis outside
the #ifdef and added a comment (see below).  Bram: would you merge
this into the Vim code or would you rather I just apply it to the
MacVim code?

Björn


diff --git a/src/fileio.c b/src/fileio.c
index 3163a74..239a37c 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -5229,11 +5229,12 @@ msg_add_lines(insert_space, lnum, nchars)
     if (shortmess(SHM_LINES))
        sprintf((char *)p,
 #ifdef LONG_LONG_OFF_T
-               "%ldL, %lldC",
+               "%ldL, %lldC", lnum, nchars
 #else
-               "%ldL, %ldC",
+               /* Explicit typecast avoids warning on Mac OS X 10.6 */
+               "%ldL, %ldC", lnum, (long)nchars
 #endif
-               lnum, nchars);
+               );
     else
     {
        if (lnum == 1)
@@ -5246,11 +5247,12 @@ msg_add_lines(insert_space, lnum, nchars)
        else
            sprintf((char *)p,
 #ifdef LONG_LONG_OFF_T
-                   _("%lld characters"),
+                   _("%lld characters"), nchars
 #else
-                   _("%ld characters"),
+                   /* Explicit typecast avoids warning on Mac OS X 10.6 */
+                   _("%ld characters"), (long)nchars
 #endif
-                   nchars);
+                   );
     }
 }

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui