Ulf Ochsenfahrt <[EMAIL PROTECTED]> writes:

[...]

> What about inifinite loops? The linked list could also loop back to itself.

Is there any guarantee that a std::list is a linked list?  Is it
possible to produce a cycle in a std::list?  Is the behaviour of
size() on such a list defined?

[...]

> Compiler writers are usually very conservative. I would guess that
> the optimizer makes the program behave differently' is a serious
> enough issue.

Even for a program whose behaviour is undefined?  Sometimes it
matters: if there's enough code that's relying on the undefined
behaviour.  In this case I doubt they'd care.

>> 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.

The standard library is part of the language specification, so the
compiler is allowed to know about it.  An implementation might use an
O(n) size() for unoptimized builds and an O(1) implementation when
optimizing.  (I doubt there's any reason to do that, but I don't think
it would be forbidden.)


_______________________________________________
Monotone-devel mailing list
Monotone-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/monotone-devel

Reply via email to