Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail NNTP-Posting-Date: Thu, 21 Jun 2012 17:23:59 -0500 From: Gareth Owen Newsgroups: comp.lang.c Subject: Re: Design decisions References: Date: Thu, 21 Jun 2012 23:23:59 +0100 Message-ID: <87a9zwb8xs.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:dYs6mS4ZHrAMe/ICQNHU9f015Fg= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Lines: 26 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-2FF91hVkjspYjpCXwNicY9InIttfQyBlsjOXQv4hKUdq5j9awEagO9KUWOH9aPujWZqIR3iwPikXhIQ!mszBB3ZlYxluakHalDV7zV40jf6DCLt1kaqDReEcKJS9t6NEFKF8YbbpRsu/1j8+uCzZ 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: 2029 Xref: csiph.com comp.lang.c:22507 "BartC" writes: > How does C++ deal with it? Most (all?) C++ STL containers give a bounds-checked accessor that returns a reference on success, but throws an exception on out-of-bounds access (I assume that's the main failure condition Jacob has in mind for GetElement also). Exceptions give you a return path which, when combined with well encapsulated objects, automatically cleans up any resources. Of course, writing such exception-safe objects is a non-trivial undertaking. jacob navia writes: > Before returning, the "GetElement" API calls the error function and > will return ONLY IF the error function returns. What do you have in mind for a well designed, non-returning error function. Obviously one that calls abort()/exit() would work but what else? Could the error function provide a default value (e.g. out-of-bounds access always returns a 0 value, or attempts to expand the vector and pad with zero)? Or were you thinking in terms of longjmp()ing to some prior state?