Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #41228
| From | Cholo Lennon <chololennon@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: asserts considered harmful |
| Date | 2016-02-24 16:49 -0300 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <nal1gm$bpt$1@gioia.aioe.org> (permalink) |
| References | <8_2dnQWwaKOXRlHLnZ2dnUU7-dudnZ2d@giganews.com> <dj44lnFj7j3U2@mid.individual.net> |
On 02/23/2016 07:27 PM, Ian Collins wrote: > Mr Flibble wrote: >> Code containing asserts will behave differently depending on whether or >> not the macro NDEBUG is defined. This is dangerous as it may result in >> undetected bugs in a release build manifesting as undefined behaviour >> that doesn't cause a straight crash but does something more serious. > > So don't change NDEBUG in your release builds. > Long time ago I had to deal with a nasty assert enabled in release builds. From time to time (very seldom) our application crashed in a production environment. The application used an internal dynamic library which in turns used a third party library. The latter had an assert for an unusual situation (a network packet not recognized). The author decided that instead of just ignoring the packet o logging it, he had to assert. It was a bad decision combined with asserts enabled by default in release build. assert (I'm talking about C assert) must be used carefully and IMHO must not be enabled in release. If you need to report unsusual situations use exceptions or create a new assert macro on top of C++ exceptions. In my personal case I'm using asserts for pre/post conditions (expects/ensures) in a similar way to thoses described here: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md (from the link see "State preconditions (if any)" and "State postconditions") My macros are build on top of C++ exceptions and can be enabled/disabled in release builds. Regards -- Cholo Lennon Bs.As. ARG
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-23 22:19 +0000
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-24 11:27 +1300
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-23 22:32 +0000
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-24 11:44 +1300
Re: asserts considered harmful Cholo Lennon <chololennon@hotmail.com> - 2016-02-24 16:49 -0300
Re: asserts considered harmful "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-24 00:00 +0100
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-23 23:20 +0000
Re: asserts considered harmful "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-24 01:02 +0100
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-24 00:17 +0000
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-24 13:25 +1300
Re: asserts considered harmful Vir Campestris <vir.campestris@invalid.invalid> - 2016-02-24 21:27 +0000
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-25 10:59 +1300
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-24 14:13 -0800
Re: asserts considered harmful scott@slp53.sl.home (Scott Lurndal) - 2016-02-25 00:12 +0000
Re: asserts considered harmful David Brown <david.brown@hesbynett.no> - 2016-02-25 01:23 +0100
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-25 15:29 +1300
Re: asserts considered harmful Vir Campestris <vir.campestris@invalid.invalid> - 2016-02-25 23:05 +0000
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-26 19:41 +1300
Re: asserts considered harmful David Brown <david.brown@hesbynett.no> - 2016-02-26 17:11 +0100
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-24 17:32 -0800
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-24 13:00 +1300
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-24 00:24 +0000
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-24 13:34 +1300
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-24 01:21 +0000
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-24 14:55 +1300
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-23 18:47 -0800
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-24 17:52 +0000
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-24 11:14 -0800
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-24 19:42 +0000
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-24 12:58 -0800
Re: asserts considered harmful Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-02-24 21:49 +0000
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-24 14:03 -0800
Re: asserts considered harmful Paavo Helde <myfirstname@osa.pri.ee> - 2016-02-24 11:48 +0200
Re: asserts considered harmful Ian Collins <ian-news@hotmail.com> - 2016-02-24 23:14 +1300
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-24 05:52 -0800
Re: asserts considered harmful woodbrian77@gmail.com - 2016-03-09 11:32 -0800
Re: asserts considered harmful mark <mark@invalid.invalid> - 2016-02-24 14:43 +0100
Re: asserts considered harmful Öö Tiib <ootiib@hot.ee> - 2016-02-24 06:22 -0800
csiph-web