[M3devel] Posix < 0 vs. # 0 vs. = -1?

Jay K jay.krell at cornell.edu
Mon Apr 19 06:43:54 CEST 2010


 > much cheaper

 

Ah. I hadn't considered that.

It looks like we might gain commonality in socket code though by checking for a specific value.

C:\dev2\cm3.2\m3-libs\m3core\src\win32\WinSock.i3(293):  SOCKET_ERROR   = -1;


 

 - Jay
 


From: hosking at cs.purdue.edu
Date: Sun, 18 Apr 2010 15:09:00 -0400
To: jay.krell at cornell.edu
CC: m3devel at elegosoft.com
Subject: Re: [M3devel] Posix < 0 vs. # 0 vs. = -1?

Checking < 0 is much cheaper than checking = -1.
C idioms typically check < 0.

-1 is simply a convenient negative value to return.

Leave it as is.






On 18 Apr 2010, at 09:57, Jay K wrote:

Posix often says:
 function foo() returns 0 for success, -1 for error
 
 m3core/libm3/etc, often say if foo() < 0 or if foo() # 0 "instead".
 Generally ok to tighten these up to "= -1", perhaps upon checking manpages,
  or a known rat's nest of inconsistencies?

 - Jay


 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100419/ac2cd1e9/attachment-0002.html>


More information about the M3devel mailing list