Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #67918
| Subject | Re: Why does this work on Xcode ??? |
|---|---|
| Newsgroups | comp.lang.c++ |
| References | (10 earlier) <87pnkwakex.fsf@bsb.me.uk> <qjnt6f$e14$1@dont-email.me> <qjoplk$ep$1@dont-email.me> <qjotnh$p13$1@dont-email.me> <qjpki9$vhs$1@dont-email.me> |
| From | Richard Damon <Richard@Damon-Family.org> |
| Message-ID | <Cn_7F.31037$O63.25583@fx26.iad> (permalink) |
| Organization | Forte - www.forteinc.com |
| Date | 2019-08-23 19:10 -0400 |
On 8/23/19 5:07 PM, Alf P. Steinbach wrote:
> On 23.08.2019 16:37, David Brown wrote:
>> On 23/08/2019 15:28, James Kuyper wrote:
>>> On 8/23/19 1:22 AM, Alf P. Steinbach wrote:
>>>> On 23.08.2019 00:45, Ben Bacarisse wrote:
>>>>> "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> writes:
>>>>> <cut>
>>>>>> And I don't think you think you're smarter than everybody else in
>>>>>> this
>>>>>> group just for holding an opinion on UB that nobody else here shares.
>>>>>
>>>>> Why do you think no one else shares Tim's opinion?
>>>>
>>>> Because he's been arguing his view for a very long time and nobody's
>>>> supported him.
>>>
>>> I normally try (and often fail) to avoid paying attention to his posts,
>>> because I've found discussions with him to be unproductive - when I
>>> discuss my disagreements with him, we usually both end up wasting a lot
>>> of time failing to convince each other. He's a lot like you in that
>>> regard.
>>>
>>> He has a strong tendency to elevate what he believes to be the
>>> committee's intent to play a larger role in the interpretation of the
>>> standard than I think appropriate. This can be particularly annoying if
>>> I disagree with him about what that intent was.
>>> If the standard's wording is in conflict with (or even simply fails to
>>> clearly express) the committee's intent, then that wording should be
>>> corrected to clearly express that intent - but that discrepancy doesn't
>>> change the meaning of the words that they actually wrote.
>>>
>>> However, he is very knowledgeable about the standard, and he is correct
>>> about the pre-eminence of a program's observable behavior. The
>>> standard's definition of "observable behavior" is not "behavior which
>>> can be observed" - it's far more specific than that:
>>>
>>> "The least requirements on a conforming implementation are:
>>> — Accesses through volatile glvalues are evaluated strictly according to
>>> the rules of the abstract machine.
>>> — At program termination, all data written into files shall be identical
>>> to one of the possible results that
>>> execution of the program according to the abstract semantics would have
>>> produced.
>>> — The input and output dynamics of interactive devices shall take place
>>> in such a fashion that prompting
>>> output is actually delivered before a program waits for input. What
>>> constitutes an interactive device is
>>> implementation-defined.
>>> These collectively are referred to as the observable behavior of the
>>> program. ..." (4.6p7).
>>>
>>> The term "observable behavior" is in italics, an ISO convention
>>> indicating that this sentence is the official definition of that term.
>>> In the context of the C++ standard, that definition overrides any
>>> alternative interpretation that might otherwise seem appropriate.
>>>
>>> Note that the amount of stack space taken up by a program does not
>>> qualify as "observable behavior".
>>>
>>> The standard very explicitly says "The semantic descriptions in this
>>> International Standard define a parameterized nondeterministic abstract
>>> machine. This International Standard places no requirement on the
>>> structure of conforming implementations. In particular, they need not
>>> copy or emulate the structure of the abstract machine. Rather,
>>> conforming implementations are required to emulate (only) the observable
>>> behavior of the abstract machine as explained below." (4.6p1).
>>>
>>> So if the same observable behavior can be achieved by using either an
>>> iterative or a recursive algorithm, an implementation is free to use
>>> either of those algorithms to achieve it, regardless of which algorithm
>>> you actually expressed in your code. The fact that one algorithm runs a
>>> higher risk of running out of stack space than the other imposes no
>>> requirement on the implementation to avoid that risk (or to embrace it,
>>> for that matter).
>>>
>>
>> Since we are expressing opinions - regardless of how much or little they
>> may be worth - I agree with James here. And as far as I can see, it is
>> the same as Tim has been saying in this regard.
>>
>> Usually, changing an iterative algorithm into a recursive one will be a
>> pessimisation, taking more space and run-time. So it is highly unlikely
>> for a compiler to do this sort of thing - it would quickly become an
>> unpopular tool. But it is allowed to do so.
>
> As an example, rewriting a function with loop that uses a fixed size
> storage known at compile time, to a recursive function that uses storage
> proportional to the function argument, changes the behavior.
>
> With the original code one is guaranteed that it will complete.
>
> With the recursive one one is not guaranteed completion, because for
> large enough values of the parameter it will run out of stack space, an
> implementation limit.
>
> * * *
>
> Essentially the argument about observable behavior is therefore that a
> compiler is formally permitted to change a program that guarantees a
> result if it compiles and loads, into a program that almost guaranteed
> does not produce a correct result.
>
> That's a perpetuum mobile construction argument. One doesn't necessarily
> know where someone's logic went astray so that they ended up with a
> perpetuum mobile design, but the end result is just not reality: it's
> absurd. Somewhere in that argument there's necessarily something wrong,
> and that's not a QoI issue.
>
>
>> In the same way, between "int a = b + c;" and "int d = a * 2;", the
>> compiler is allowed to insert code calculating the first hundred digits
>> of pi - including the stack space needed for the job.
>
> No, that's not the same way.
>
> In this example a fixed storage requirement is not changed to a
> requirement of storage depending on a parameter.
>
>
>> It would be an
>> unpopular tool, but this would not affect the observable behaviour and
>> thus it would not affect the conformance of the compiler.
>
> It would affect observable behavior. One would get wrong results or
> crashes. Instead of with a conforming compiler, correct results.
>
>
>> The standards do not impose any requirements on quality of
>> implementation (though they have a few hints here and there) - that is
>> up to the user.
>
> That's right, but this isn't QoI, it's about correctness.
>
>
> Cheers!,
>
> - Alf
The Standards unfortunately leave a LOT to QoI.
For instance, as far as I know, the compiler would be free to implement
unsigned i = 1;
unsigned j = 5;
unsigned k = i + j;
as
k = __add_uint(i, j);
where __add_uint() was defined as:
unsigned __add_uint(unsigned i, unsigned j) {
if(j) return __add_uint(++i, --j);
else return i;
}
You might even need something like this (but maybe iterative instead of
recursive) for a processor with very limited arithmetic operations (just
increment/decrement).
One such an implementation, the program
int main() {
unsigned i = 1U + 65000U;
}
might fail due to exhaustion of resources, and that is ok by the
standard. The Standard just requires that there be ONE program that
reaches all of the specified resource limits that the implementation can
process, any other program is allowed to fail for resource limits. This
'one program' rule is one of the big holes in the Standard (at least in
my opinion).
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why does this work on Xcode ??? Bob Langelaan <bobl0456@gmail.com> - 2019-07-16 22:03 -0700
Re: Why does this work on Xcode ??? Paavo Helde <myfirstname@osa.pri.ee> - 2019-07-17 08:46 +0300
Re: Why does this work on Xcode ??? Öö Tiib <ootiib@hot.ee> - 2019-07-17 00:06 -0700
Re: Why does this work on Xcode ??? Öö Tiib <ootiib@hot.ee> - 2019-07-17 01:44 -0700
Re: Why does this work on Xcode ??? Juha Nieminen <nospam@thanks.invalid> - 2019-07-17 07:46 +0000
Re: Why does this work on Xcode ??? James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-07-17 09:12 -0400
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-07-17 17:01 +0200
Re: Why does this work on Xcode ??? Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-07-17 22:15 +0100
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-07-17 23:29 +0200
Re: Why does this work on Xcode ??? Christian Gollwitzer <auriocus@gmx.de> - 2019-07-19 08:27 +0200
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-07-19 09:09 +0200
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-07-19 09:24 +0200
Re: Why does this work on Xcode ??? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-08-10 11:18 -0700
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-08-10 21:05 +0200
Re: Why does this work on Xcode ??? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-08-22 10:28 -0700
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-08-22 19:50 +0200
Re: Why does this work on Xcode ??? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-08-22 23:45 +0100
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-08-23 07:22 +0200
Re: Why does this work on Xcode ??? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-08-23 13:12 +0100
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-08-23 16:02 +0200
Re: Why does this work on Xcode ??? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-09-18 08:50 -0700
Re: Why does this work on Xcode ??? James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-08-23 09:28 -0400
Re: Why does this work on Xcode ??? David Brown <david.brown@hesbynett.no> - 2019-08-23 16:37 +0200
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-08-23 23:07 +0200
Re: Why does this work on Xcode ??? Richard Damon <Richard@Damon-Family.org> - 2019-08-23 19:10 -0400
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-08-24 06:49 +0200
Re: Why does this work on Xcode ??? James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-08-23 19:49 -0400
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-08-24 06:45 +0200
Re: Why does this work on Xcode ??? David Brown <david.brown@hesbynett.no> - 2019-08-25 12:06 +0200
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-08-25 13:25 +0200
Re: Why does this work on Xcode ??? David Brown <david.brown@hesbynett.no> - 2019-08-25 15:11 +0200
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-08-25 17:12 +0200
Re: Why does this work on Xcode ??? David Brown <david.brown@hesbynett.no> - 2019-08-25 23:32 +0200
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-08-26 11:51 +0200
Re: Why does this work on Xcode ??? David Brown <david.brown@hesbynett.no> - 2019-08-26 13:26 +0200
Re: Why does this work on Xcode ??? David Brown <david.brown@hesbynett.no> - 2019-08-25 11:36 +0200
Re: Why does this work on Xcode ??? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-08-25 13:27 +0200
Re: Why does this work on Xcode ??? David Brown <david.brown@hesbynett.no> - 2019-08-25 15:15 +0200
Re: Why does this work on Xcode ??? James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-08-26 00:43 -0400
Re: Why does this work on Xcode ??? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-08-24 04:58 -0700
Re: Why does this work on Xcode ??? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-08-26 09:53 -0700
Re: Why does this work on Xcode ??? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-08-28 18:03 -0700
Re: Why does this work on Xcode ??? Öö Tiib <ootiib@hot.ee> - 2019-07-19 00:20 -0700
Re: Why does this work on Xcode ??? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-08-09 07:41 -0700
Re: Why does this work on Xcode ??? Bonita Montero <Bonita.Montero@gmail.com> - 2019-08-24 19:49 +0200
Re: Why does this work on Xcode ??? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-07-21 11:41 +0000
Re: Why does this work on Xcode ??? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-08-10 09:29 -0700
csiph-web