Re: diagnosing C errors, was Alternative C compilers on x86_64 Linux?

BartC <bc@freeuk.com>
Fri, 9 Sep 2016 12:31:17 +0100

          From comp.compilers

Related articles
Alternative C compilers on x86_64 Linux? arnold@skeeve.com (2016-09-02)
Re: Alternative C compilers on x86_64 Linux? jacob@jacob.remcomp.fr (jacobnavia) (2016-09-05)
Re: Alternative C compilers on x86_64 Linux? alexfrunews@gmail.com (2016-09-05)
Re: diagnosing C errors, was Alternative C compilers on x86_64 Linux? bc@freeuk.com (BartC) (2016-09-09)
Re: diagnosing C errors, was Alternative C compilers on x86_64 Linux? 221-501-9011@kylheku.com (Kaz Kylheku) (2016-09-09)
Re: diagnosing C errors, was Alternative C compilers on x86_64 Linux? DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2016-09-10)
| List of all articles for this month |

From: BartC <bc@freeuk.com>
Newsgroups: comp.compilers
Date: Fri, 9 Sep 2016 12:31:17 +0100
Organization: A noiseless patient Spider
References: 16-09-001 16-09-002 16-09-008
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

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


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.