Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!sdd.hp.com!ucsd!ucbvax!van-bc!ubc-cs!alberta!hoover From: hoover@cs.UAlberta.CA (Jim Hoover) Newsgroups: comp.lang.perl Subject: Re: Yet another perl portability bug Message-ID: <1990Dec12.042542.28733@cs.UAlberta.CA> Date: 12 Dec 90 04:25:42 GMT References: <1990Dec11.052604.21319@cs.UAlberta.CA> <1990Dec11.220809.20201@melba.bby.oz.au> Sender: news@cs.UAlberta.CA (News Administrator) Organization: University of Alberta, Edmonton, Canada Lines: 52 In article <1990Dec11.220809.20201@melba.bby.oz.au> gnb@bby.oz.au (Gregory N. Bond) writes: >>>>>> On 11 Dec 90 05:26:04 GMT, hoover@cs.UAlberta.CA (Jim Hoover) said: > >Jim> 746c747,748 >Jim> < return retval; >Jim> --- >Jim> /* FIX - memcmp is not guaranteed to return -1 0 +1, just sign */ >Jim> return (retval > 0) ? +1 : -1; > >Bzzt. What it retval == 0? You mean > return (retval > 0) ? 1 : (retval < 0) ? -1 : 0; > ... Sorry, I seem to have become affected by the current trend toward obscurity disguised as cleverness. I could have at least practiced what I preach and given more context :) Within the context of the fix, retval cannot be 0, so the single test suffices. Here is the full context: if (str1->str_cur < str2->str_cur) { if (retval = memcmp(str1->str_ptr, str2->str_ptr, str1->str_cur)) /* HJH - memcmp is not guaranteed to return -1 0 +1, just sign */ return (retval > 0) ? +1 : -1; else return -1; } else if (retval = memcmp(str1->str_ptr, str2->str_ptr, str2->str_cur)) /* HJH - memcmp is not guaranteed to return -1 0 +1, just sign */ return (retval > 0) ? +1 : -1; else if (str1->str_cur == str2->str_cur) return 0; else return 1; (The context, by the way, reflects a two's complement bias that is ubiquitous in C code. How much stuff breaks if you switch to a signed-magnitude machine with +- 0?) >-- >Gregory Bond, Burdett Buckeridge & Young Ltd, Melbourne, Australia >Internet: gnb@melba.bby.oz.au non-MX: gnb%melba.bby.oz@uunet.uu.net >Uucp: {uunet,pyramid,ubc-cs,ukc,mcvax,prlb2,nttlab...}!munnari!melba.bby.oz!gnb -- Prof. Jim Hoover | Office +1 403 492 5401 or 5290 Dept. of Computing Science | FAX +1 403 492 1071 University of Alberta | hoover@cs.ualberta.ca Edmonton, Alberta, Canada T6G 2H1 |