Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 16 Sep 2011 16:53:01 -0500 Message-ID: <4E73C53F.1648@mindspring.com> Date: Fri, 16 Sep 2011 17:53:03 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: Reversing a linked list References: <0.58bc9b9dbe16eaa00140.20110916125127BST.87sjnwyabk.fsf@bsb.me.uk> <51096d0a-12c9-4eb2-9b85-cd42c2c79513@r21g2000yqr.googlegroups.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 35 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.156.228.129 X-Trace: sv3-FPu/McKC8qhKWwtuWiX7TNNAy0BwHWft6ZawdjJyKRWtFw8R2mNn3PfLM7Sw87jSyzT8sJvINaEb4ej!6Dku4zF2H5e2r+vCALO9uemgoXI4lxAvSv68/5bpaoMuWjjdQ5fw2A7L7Vn27b5aOFnc/eYcWZK5!Tk3Xg8x17ZI= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2278 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:10354 ImpalerCore wrote: > From my perspective, a precondition for a function is independent of > the method used to handle its violations. This is what contrasts the > defensive programming from the design by contract paradigm. They both > see the same function preconditions; they respond to them differently. > > Take 'size_t strlen( const char* str )' for example. > > \code > size_t strlen( const char* str ) > { > const char* s; > > for ( s = str; *s != '\0'; ++s ) > ; > > return s - str; > } > \endcode > > If I were to list the preconditions, I would say that 'str' must > reference a character buffer and that buffer contain a terminating > '\0' character. Some of these preconditions are testable, others are > not (when a memory debugger is not present). It is difficult to > impossible to verify whether a fixed-width buffer passed to strlen > contains a '\0' without potentially generating a memory access > violation. Also as a precondition, the length of the string to be measured by that version of strlen, should not be greater than PTRDIFF_MAX. -- pete