2008/8/24 Bram Moolenaar <[EMAIL PROTECTED]>: > Robert Webb wrote: > >> The help for sort() says the following with respect to the function >> reference argument: >> >> ...The function is invoked with two >> items as argument and must return zero if they are equal, 1 if >> the first one sorts after the second one, -1 if the first one >> sorts before the second one. Example: >> func MyCompare(i1, i2) >> return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 >> endfunc >> >> Does it really have to return -1, 0, or 1? Or is it OK to just return >> negative, 0 or positive? That way it becomes easier: >> >> func MyCompare(i1, i2) >> return a:il - a:i2 >> endfunc >> >> I think the docs should be updated if this is how it behaves. And if >> not, the docs and the code should be updated so it does :-) > > Vim uses qsort(). My man page says that the value of the compare > function can be any value less than, equal to or bigger than zero. > Is it like that on all systems?
More specifically, qsort expects a signed int. If MyCompare returns 1E37 - 1E20, it's probably not going to have a happy ending. -- /George V. Reilly [EMAIL PROTECTED] http://www.georgevreilly.com/blog http://blogs.cozi.com/tech --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---