From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Bob Duff Newsgroups: comp.lang.ada Subject: Re: Languages don't matter. A mathematical refutation Date: Fri, 03 Apr 2015 13:33:21 -0400 Organization: A noiseless patient Spider Message-ID: <87twwxxgke.fsf@theworld.com> References: <87h9t95cly.fsf@jester.gateway.sonic.net> <04f0759d-0377-4408-a141-6ad178f055ed@googlegroups.com> <871tk1z62n.fsf@theworld.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="88eb400c84e19b2ff60f0f64a30a0876"; logging-data="26121"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18PMzGhcYdgTCI5laRU6okA" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:UQbG5+2vMH1hJ/E1KAsOE+ucYfw= sha1:CaOWuaLcv0dGXNaTAvn0tsrYL/I= Xref: number.nntp.giganews.com comp.lang.ada:192706 Date: 2015-04-03T13:33:21-04:00 List-Id: "J-P. Rosen" writes: > Le 03/04/2015 15:37, Bob Duff a écrit : >> Assembly language: Semantics are defined in terms of the generated >> machine code. > OK > >> High-level language: Semantics are defined in terms of what the program >> does. > I don't understand this. Do you mean "specification: observed behaviour > of a program" ? ;-) Yes. In an assembly language, if you write "ADD", the semantics are that an ADD instruction is generated in the machine code. But in a high-level langauge, if you write "+", the language definition doesn't say anything about what machine instruction(s) are emitted. And in practice, you might get a shift, or you might get no instructions at all. C is clearly in the second category. >> Those are how I understand the terms, and I think how they are commonly >> understood. I can't think of any other useful definitions. >> C is clearly a high-level language, by those definitions. > Not clearly. A number of things (handling of integer overflows, > semantics of %, dereferencing the null pointer...) are defined in the > language as "like the machine does" (this is spelled: implementation > defined). Unless it has changed in recent versions of C ? No, no C standard has ever said "like the machine does". Those things are defined as "undefined behavior" in C, and that does not mean "like the machine does", it means "anything can happen" (as far as the C standard is concerned). "Like the machine does" is not even meaningful in a high-level language. What the machine does depends on what code the compiler generates. For example, on x86, a C compiler might generate an ADD (so you get wraparound semantics). Or it might generate ADD followed by TRAPV (so the program crashes on overflow). Or it might turn this: if (X + 1 <= 0) do_something(); into: do_something(); if it knows X >= 0 before the 'if'. gcc actually does things of that nature. I've seen people get really annoyed at gcc for that sort of thing, but I think their beef is with the language definition -- they should use a language that defines the behavior of overflow. If it can prove X = the max integer, it can remove the entire if statement. - Bob