tag:blogger.com,1999:blog-3993498847203183398.post3710217340179745222..comments2024-03-28T09:19:27.451+00:00Comments on RevK<sup>®</sup>'s ramblings: CPP why do you hate me?RevKhttp://www.blogger.com/profile/12369263214193333422noreply@blogger.comBlogger13125tag:blogger.com,1999:blog-3993498847203183398.post-4109669768652975852016-04-26T14:24:26.102+01:002016-04-26T14:24:26.102+01:00Glad I was not being totally daft then :-) I think...Glad I was not being totally daft then :-) I think a custom assert code of my own with stack trace and so on it probably better.RevKhttps://www.blogger.com/profile/12369263214193333422noreply@blogger.comtag:blogger.com,1999:blog-3993498847203183398.post-9721864673625216402016-04-26T14:22:53.392+01:002016-04-26T14:22:53.392+01:00The NDEBUG "feature" (more like madness)...The NDEBUG "feature" (more like madness) is why I've never used assert() in 30 years of C programming. Until now that is, my new place mandates it for error handling. I have been unable to persuade them this is a bad idea (they've been doing it for 15 years and are in denial there's a problem with it).Owen Smithhttps://www.blogger.com/profile/00890951742186614705noreply@blogger.comtag:blogger.com,1999:blog-3993498847203183398.post-42240291155218708272016-04-26T12:22:39.935+01:002016-04-26T12:22:39.935+01:00Many options I know - I like C though :-)Many options I know - I like C though :-)RevKhttps://www.blogger.com/profile/12369263214193333422noreply@blogger.comtag:blogger.com,1999:blog-3993498847203183398.post-34194427819436869672016-04-26T12:21:16.661+01:002016-04-26T12:21:16.661+01:00If this is server-side stuff, you really ought to ...If this is server-side stuff, you really ought to look at something more modern than 'C' - these sort of problems are just dealt with so much better in modern languages / frameworks.Will Deanhttps://www.blogger.com/profile/15515078919433985452noreply@blogger.comtag:blogger.com,1999:blog-3993498847203183398.post-54590687984153841782016-04-26T11:22:43.059+01:002016-04-26T11:22:43.059+01:00Indeed, I am even thinking I need an assert type f...Indeed, I am even thinking I need an assert type function that not only reports and exist but also does stack trace so I know how it got there. This is, indeed, important in live code as it quickly identifies the problems that need addressing urgently as they are in a live system!RevKhttps://www.blogger.com/profile/12369263214193333422noreply@blogger.comtag:blogger.com,1999:blog-3993498847203183398.post-30147715122110504642016-04-26T11:11:20.784+01:002016-04-26T11:11:20.784+01:00I tend to use something similar for any call which...I tend to use something similar for any call which shouldn't fail but theoretically could, to make sure I do handle that situation sanely - I remembered about assert() getting compiled out on non-debug builds, though.<br /><br />I'm not convinced of the logic of that exclusion these days (aren't most "unlikely" scenarios like that actually *more* likely to need to be caught in public releases of software than in internal test builds?!) - an "always_assert_even_in_release_mode" does seem useful too. In my recent Go coding, I've tended to include a simple "checkdie" function, which checks for error values and dies with an appropriate message on failure. So, "dostuff()" which might return an error becomes a simple "checkdie(dostuff())" which quits if that operation fails - quite sensible for batch data conversion, which is where I'm using Go at the moment.<br /><br />The discussion of this on StackOverflow also included someone pointing out changing lots of settings between the debug internal test build and the public release seems unwise, better to test the version you'll be shipping and vice versa as far as possible.jas88https://www.blogger.com/profile/05563592458314214904noreply@blogger.comtag:blogger.com,1999:blog-3993498847203183398.post-6950082477382450912016-04-26T08:10:10.480+01:002016-04-26T08:10:10.480+01:00gccgccRevKhttps://www.blogger.com/profile/12369263214193333422noreply@blogger.comtag:blogger.com,1999:blog-3993498847203183398.post-21026904507150736542016-04-26T08:09:50.401+01:002016-04-26T08:09:50.401+01:00To be honest I am not up to speed on all of the cx...To be honest I am not up to speed on all of the cxx attributes and was thinking it would be handy to define some of these things, yes. So thanks for the tip.RevKhttps://www.blogger.com/profile/12369263214193333422noreply@blogger.comtag:blogger.com,1999:blog-3993498847203183398.post-22477445060236405222016-04-26T01:47:49.142+01:002016-04-26T01:47:49.142+01:00On the assumption that you're using either GCC...On the assumption that you're using either GCC or Clang, did you annotate the function declaration?<br /><br />__attribute__ ((format (printf, 2, 3))) <br />__attribute__ ((nonnull (1)))Anonymoushttps://www.blogger.com/profile/11266267115878176577noreply@blogger.comtag:blogger.com,1999:blog-3993498847203183398.post-16469087433739408222016-04-25T16:56:08.830+01:002016-04-25T16:56:08.830+01:00Indeed! I am checking any other places I have mis-...Indeed! I am checking any other places I have mis-used assert now :-)RevKhttps://www.blogger.com/profile/12369263214193333422noreply@blogger.comtag:blogger.com,1999:blog-3993498847203183398.post-10483528664892489862016-04-25T16:53:51.650+01:002016-04-25T16:53:51.650+01:00The reason for evaluating to nothing when NDEBUG i...The reason for evaluating to nothing when NDEBUG is defined is because the arguments to assert() may contain expensive computations to be verified by the assertion, and you don't want to waste time doing those computations when assertions are disabled.<br /><br />The assumption was that nobody would be so silly as to put stuff with side-effects into an assert and then expect them to persist even when you wanted the assert to do nothing. The resulting decades of bugs have taught us that this assumption was in error :)Nick Alcockhttps://www.blogger.com/profile/06590610308528769844noreply@blogger.comtag:blogger.com,1999:blog-3993498847203183398.post-52087874668118270862016-04-25T15:30:44.495+01:002016-04-25T15:30:44.495+01:00Fair enough.Fair enough.RevKhttps://www.blogger.com/profile/12369263214193333422noreply@blogger.comtag:blogger.com,1999:blog-3993498847203183398.post-75797969891284905252016-04-25T15:28:40.206+01:002016-04-25T15:28:40.206+01:00assert() is designed to compile away to nothing in...assert() is designed to compile away to nothing in a release build, where NDEBUG is defined.<br /><br />It's not the right tool to verify run-time assumptions.Will Deanhttps://www.blogger.com/profile/15515078919433985452noreply@blogger.com