Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!think!barmar From: barmar@think.uucp (Barry Margolin) Newsgroups: comp.lang.c Subject: Re: Writing readable code Message-ID: <6445@think.UUCP> Date: Tue, 14-Jul-87 11:37:34 EDT Article-I.D.: think.6445 Posted: Tue Jul 14 11:37:34 1987 Date-Received: Thu, 16-Jul-87 05:38:05 EDT References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> <17171@cca.CCA.COM> <926@argus.UUCP> <1219@ius2.cs.cmu.edu> Sender: news@think.UUCP Reply-To: barmar@godot.think.com.UUCP (Barry Margolin) Organization: Thinking Machines Corporation, Cambridge, MA Lines: 14 In article <1219@ius2.cs.cmu.edu> edw@ius2.cs.cmu.edu (Eddie Wyatt) writes: > I can think of no Unix system call that doesn't return -1 on error. >So I would say that it's a pretty good bet that "if (call(...) < 0)" and >"if (call(...) == -1)" will act the same in all cases. Though, one should >always consult the man pages for return values if in doubt. The first sentence is probably correct; however, it doesn't imply the second. I recently fixed a bug in some network code that assumed the two were equivalent. It was calling the function that translates a host name into a network address, expressed as an int. The man page didn't explicitly mention that many valid addresses are negative numbers, so the programmer assumed that a <0 test would be OK. Until I fixed it, this program was unable to communicate with any hosts on internet class B and C networks.