|
From: | Ulf Ochsenfahrt |
Subject: | Re: [Monotone-devel] Re: using empty() instead of size() |
Date: | Tue, 23 Sep 2008 14:56:33 +0200 |
User-agent: | Thunderbird 2.0.0.16 (X11/20080724) |
Bruce Stephens wrote:
Ulf Ochsenfahrt <address@hidden> writes: [...]If there is an invalid pointer in the non-empty list, the program can crash.It can crash, but this is presumably in the realm of undefined behaviour, so arbitrary things are permitted to happen.If the compiler optimizes (i.e. removes) the list traversal, the program doesn't crash. Thus, the optimization would change the runtime behavior of the program.Probably, but I think that's a permitted change.
What about inifinite loops? The linked list could also loop back to itself.
I'd guess a bug report along those lines ("your optimizer caused my program not to crash!") would be unlikely to be given a high priority.
Compiler writers are usually very conservative. I would guess that 'the optimizer makes the program behave differently' is a serious enough issue.
An implementation with an O(1) implementation of size() would presumably also not crash at that point either.
True. But the compiler can't know that. The compiler only sees the code, it doesn't know what it's supposed to do.
Cheers, -- Ulf
[Prev in Thread] | Current Thread | [Next in Thread] |