Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Implementing static_assert |
| Date | 2015-05-07 22:33 +1200 |
| Message-ID | <cr0tc4Fl4ufU2@mid.individual.net> (permalink) |
| References | <midqsq$81d$1@dont-email.me> <mif6mb$ffc$1@dont-email.me> <cr0s5fFl4ufU1@mid.individual.net> <mifefa$9u3$1@dont-email.me> |
jacobnavia wrote: > Le 07/05/2015 12:13, Ian Collins a écrit : >> David Brown wrote: >>> >>> I /strongly/ disapprove of the idea of turning the static assert into a >>> run-time call if it can't be evaluated at compile-time. I am not as >>> experienced a "language lawyer" as Keith and some of the others here, >>> but I believe the C11 standards insist that the boolean expression be >>> compile-time constant - and I certainly think that /should/ be the case. >>> It is in the name - it is a /static/ assertion, and should have a >>> /static/ effect. So no matter what freedom the C11 standard may or may >>> not give, give an error message if the expression is not constant. >> >> I completely agree. If the programmer doesn't realise the expression >> can't be evaluated at compile time, they could be lulled into a false >> sense of security. A static_assert should fail a compile time, it is >> likely to be used to check the sanity of a build environment. One >> example would be a continuous integration build that is built but never >> run. >> > > 1: If the expression fails at compile time an error is issued and > compilation fails. > > 2: If the expression is not a constant expression, code is generated to > evaluate it at run time. The objective of that was to replace assert by > static assert, and (if possible) test all the asserts at compile time to > produce an error message at compile time if possible. > > For instance > > assert(sizeof(void *) == 4) > > would be tested at run time even if it could be done at compile time. > > But aparently everyone agrees that that is an error... It isn't an error, it is what assert does. What static_assert does is completely different, this is a good example of a use case for static_assert. As David mentions, it would make sense for asserts of compile time constants to be evaluated at compile time, not the other way. If I write a static_assert in my code, I want it to fail to build if the condition isn't met. As part of out continuous integration process, I build out embedded targets with the ARM-gcc tool chain as part of each build. These builds are never run, so a static_assert that doesn't do what is says on the tin is worse than useless. -- Ian Collins
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Implementing static_assert jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-06 21:44 +0200
Re: Implementing static_assert Keith Thompson <kst-u@mib.org> - 2015-05-06 13:28 -0700
Re: Implementing static_assert jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-06 22:55 +0200
Re: Implementing static_assert Keith Thompson <kst-u@mib.org> - 2015-05-06 14:30 -0700
Re: Implementing static_assert Martin Shobe <martin.shobe@yahoo.com> - 2015-05-06 18:07 -0500
Re: Implementing static_assert Keith Thompson <kst-u@mib.org> - 2015-05-06 17:34 -0700
Re: Implementing static_assert David Brown <david.brown@hesbynett.no> - 2015-05-07 09:44 +0200
Re: Implementing static_assert Tim Rentsch <txr@alumni.caltech.edu> - 2015-05-07 12:37 -0700
Re: Implementing static_assert David Brown <david.brown@hesbynett.no> - 2015-05-07 10:11 +0200
Re: Implementing static_assert Ian Collins <ian-news@hotmail.com> - 2015-05-07 22:13 +1200
Re: Implementing static_assert jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-07 12:24 +0200
Re: Implementing static_assert Ian Collins <ian-news@hotmail.com> - 2015-05-07 22:33 +1200
Re: Implementing static_assert David Brown <david.brown@hesbynett.no> - 2015-05-07 14:30 +0200
Re: Implementing static_assert Philip Lantz <prl@canterey.us> - 2015-05-07 03:53 -0700
Re: Implementing static_assert David Brown <david.brown@hesbynett.no> - 2015-05-07 14:21 +0200
Re: Implementing static_assert Keith Thompson <kst-u@mib.org> - 2015-05-07 09:11 -0700
Re: Implementing static_assert James Kuyper <jameskuyper@verizon.net> - 2015-05-07 12:30 -0400
Re: Implementing static_assert James Kuyper <jameskuyper@verizon.net> - 2015-05-07 12:55 -0400
Re: Implementing static_assert Keith Thompson <kst-u@mib.org> - 2015-05-07 09:06 -0700
Re: Implementing static_assert jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-07 19:43 +0200
Re: Implementing static_assert Tim Rentsch <txr@alumni.caltech.edu> - 2015-05-07 16:10 -0700
csiph-web