Path: csiph.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: BartC Newsgroups: comp.compilers Subject: Re: diagnosing C errors, was Alternative C compilers on x86_64 Linux? Date: Fri, 9 Sep 2016 12:31:17 +0100 Organization: A noiseless patient Spider Lines: 26 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <16-09-019@comp.compilers> References: <16-09-001@comp.compilers> <16-09-002@comp.compilers> <16-09-008@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: miucha.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="34089"; mail-complaints-to="abuse@iecc.com" Keywords: C, errors Posted-Date: 09 Sep 2016 11:51:28 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1758 On 06/09/2016 01:26, alexfrunews@gmail.com wrote: > On Sunday, September 4, 2016 at 3:56:56 PM UTC-7, jacobnavia wrote: >> Why should they care? If you write duplicate switch cases its not their >> fault, its yours. > > It is a constraint violation, and a trivial one, that the compiler > must identify and report instead of silently producing code that is > broken or appears to work by chance. This is C. There are already plenty of things that it lets through that are probably errors, and which are likely to crash the program. For example, take a pointer to an array of ints, P. You'd normally access an int by dereferencing P then applying the index: (*P)[i]. But if, by mistake, you index first then dereference: *(P[i]), then this still compiles. But is likely to go wrong badly. By contrast, an inadvertent duplicate case label is a 'soft' error; the program just won't give the expected results. It's not going to read or write all over memory it shouldn't, or at least not as directly as will happen if the compiler blatantly allows pointers (to single targets) and arrays to be interchanged. -- Bartc