monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-devel] Re: using empty() instead of size()


From: Bruce Stephens
Subject: [Monotone-devel] Re: using empty() instead of size()
Date: Tue, 23 Sep 2008 14:15:31 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

Ulf Ochsenfahrt <address@hidden> 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.)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]