Deutsch English Français Italiano |
<20250403144521.00007a92@yahoo.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Michael S <already5chosen@yahoo.com> Newsgroups: comp.lang.c Subject: Re: "A diagram of C23 basic types" Date: Thu, 3 Apr 2025 14:45:21 +0300 Organization: A noiseless patient Spider Lines: 57 Message-ID: <20250403144521.00007a92@yahoo.com> References: <87y0wjaysg.fsf@gmail.com> <vsj1m8$1f8h2$1@dont-email.me> <vsj2l9$1j0as$1@dont-email.me> <vsjef3$1u4nk$1@dont-email.me> <vsjg6t$20pdb$1@dont-email.me> <vsjjd1$23ukt$1@dont-email.me> <vsjkvb$25mtg$1@dont-email.me> <vpdHP.1828825$TBhc.94105@fx16.iad> <vslhrm$7uv3$1@dont-email.me> <vsll4b$8mfb$3@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Date: Thu, 03 Apr 2025 13:45:23 +0200 (CEST) Injection-Info: dont-email.me; posting-host="ba7dc5b2cf2e1e167d044f23588b42cf"; logging-data="1711864"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gfOJTCheC/eQ6d6LvPC1qt0iQoXVWyf4=" Cancel-Lock: sha1:3QK+ncaLSnmfTdhjRFF0GzXB1oQ= X-Newsreader: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32) Bytes: 3182 On Thu, 3 Apr 2025 11:41:31 +0200 David Brown <david.brown@hesbynett.no> wrote: > On 03/04/2025 10:45, Muttley@DastardlyHQ.org wrote: > > On Wed, 02 Apr 2025 16:16:27 GMT > > scott@slp53.sl.home (Scott Lurndal) wibbled: > >> Muttley@DastardlyHQ.org writes: > >>> On Wed, 2 Apr 2025 16:59:45 +0200 > >>> David Brown <david.brown@hesbynett.no> wibbled: > >>>> On 02/04/2025 16:05, Muttley@DastardlyHQ.org wrote: > >> ist first. > >>> > >>>> 18. "unreachable()" is now standard. > >>> > >>> Googled it - don't see the point. > >> > >> That's a defect in your understanding, not a defect in the > >> standard. > >> > >> I've found the gcc equivelent useful often in standalone > >> applications (OS, Hypervisor, standalone utilities, etc). > > > > Enlighten me then. > > > > I can't tell you what Scott uses it for, but I have used gcc's > __builtin_unreachable() a fair number of times in my coding. I use > it to inform both the compiler and human readers that a path is > unreachable: > > switch (x) { > case 1 : ... > case 2 : ... > case 3 : ... > default : __builtin_unreachable(); > } > > I can also use it to inform the compiler about data : > > if ((x < 0) || (x > 10)) __builtin_unreachable(); > // x must be 1 .. 10 > > Mostly I have it wrapped in macros that let me conveniently have > run-time checking during testing or debugging, and extra efficiency > in the code when I am confident it is bug-free. > > Good use of __builtin_unreachable() can result in smaller and faster > code, and possibly improved static error checking. It is related to > the C++23 "assume" attribute (which is also available as a gcc > extension in any C and C++ version). > > In theory, compilers can use unreachable() to generated better code. In practice, every single time I looked at compiler output, it made no difference.