Xref: csiph.com comp.arch:33295 Newsgroups: comp.arch Path: csiph.com!xmission!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!kithrup.com!mrs From: mrs@kithrup.com (Mike Stump) Subject: Re: The freedom that give us C++ and C Message-ID: Date: Fri, 29 Jan 2016 22:25:44 GMT References: Organization: Kithrup Enterprises, Ld. X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Lines: 182 In article , Nick Maclaren wrote: >In article , Mike Stump wrote: >As I stated, there was no consensus on WG14 on even what the INTENT >was, let alone what the words meant. So, I can tell you what any words in any of the language standard mean. I find it easy. I find it just like reading and understanding the words as written. Certainly, the that's the intent of the language standards themselves. So, every compiler implementor can explain what the words mean. It is a required skill set. Just ask them. A typical way to do this, is to try and read the words as best you can, and once you discover behavior of the compiler that doesn't match that, you file a bug report. The implementor will then either fix the compiler to match the behavior you want (bug fix the compiler), or he will tell you that the standard contradicts you, and cite and explain the wording to you, or he may say, that the standard doesn't specify the behavior you want and he doesn't want to make it behave in the way you want. Simple, direct, and works 100% of the time. Indeed, in the development of gcc, we have always surveyed what other compilers do and use that to help form a basis of what we think the standard says. Indeed, even when writting the C++ standard, it was common for multiple people to have 5 or 10 implementations on their laptop in the meeting and anytime we read the wording of either the C or C++ standard, we could fire up those people to answer tricky questions that were less clear, or indeed turn to the actual implementor and just ask them directly. As we found discrepancies between implementations, we would file bugs against implementations to have them fix their bugs, and/or even improve the wording in the standard to make it more clear, what was meant. >C++ is a lot better than C, In this one area, I don't think it is all that better. In the C++ standard, we merely sought to write down our understanding of C for the most part. Sometimes we reused identical language, sometimes we had to elaborate to form a slightly more comlete model of something as we needed just a hair more precision in the words. Sometimes we wrote clearer words that are just what we thought the C standard meant, and folks might like the clarity, but the intent in most of those cases wasn't to change the semantics at all. Anyway, now, lets get down into the detail. Let me quote from the C++ standard: In general, the semantics of volatile are intended to be the same in C++ as they are in C. So, you can read the C++ standard to understand the C standard. If you did find C++ to be easier for you to understand, trivially you can understand the C standard merely by reading the C++ standard. Anyway, here are the C++ semantics for volatile, they are so trivial, that I can just directly state them here in their entirety: 6 The observable behavior of the abstract machine is its sequence of reads and writes to volatile data That's it. Kinda simple. In C, it's the same, though, different wording is used: Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects,11) which are changes in the state of the execution environment. The meaning is the same. From here, all you then need to understand is what does access and modify mean and that is data. Access means a memory read of bytes (if you know assembly) and write means a memory write of bytes (if you know assembly). In C++, data is an object. And object is a sequence of one or more bytes. And a byte is 8 or more contiguous bits. And a bit is a single value that is either 0 or 1. Again, if this to hard for you to understand, I can elaborate on any of these things. They aren't meant to be tricky or hard to understand. In C (and C++), a memory write is embodied by constructs like: a = 1; This will write the value 1 into the bytes allocated to hold the value for the variable a. That is an example of a memory write. A read is similarly not meant to be all that tricky: b = a; is a memory read of a. That's just about the entirely of volatile. Kinda simple stuff. Not meant to be hard to understand or unreachable by a causual reading of the text. >but its wording is still extremely ambiguous. The problem with both >is that there is no clear (let alone precise) specification of what >the abstract machine IS. That is you being disingenuous. Let me give you a concrete example: 5.13 Bitwise inclusive OR operator [expr.or] 1 inclusive-or-expression: exclusive-or-expression inclusive-or-expression | exclusive-or-expression The usual arithmetic conversions are performed; the result is the bit- wise inclusive function of its operands. Here, we all know what bitwise inclusive or is, and we all know how to write assembly (or machine code) for it. A hard core math person could formalize it all the way down for you in a way that is not able to be misunderstood (except by an idiot). Further, I bet there are 3 or more people that could lay out gates to accomplish that operation here. The above _is_ a description of the C++ abstract machine. It is perfectly clear, it is unambigious, it is precise. That is one sentence of the standard. There are more, but they all are of that exact same form. Each merely places requirements on an implementation of the standard. No more, no less. The requirements placed, are the requirements stated. >To take one simple example, where I can witness that the intent of >the majority of WG14 changed between C90 and C11 (neither being a >consensus), and where not everyone in WG21 is agreed, either, either: >evaluate A+B+C. > >What order are those values required to be loaded in, for the case >where they are all volatile? The order as stated directly by the requirements as stated in the standard: 4 Except where noted, the order of evaluation of operands of individual operators and subexpressions of individual expressions, and the order in which side effects take place, is unspecified. simple, no? There is a hard core definition of unspecified, if you don't know what that word means. I can elaborate, if needed. That's it, and it _is_ that simple. That covers C and that covers C++, as I quoted both. This is non-controversial and absolutely no one can disagree with me (except idiots). So, trivial, either, your memory of those events is faulty, or, you were surrounded by idiots. Now, my insight into the above words isn't special. My claim is that most people that can read English, can read and understand those words. Ask a 10 year old that doesn't know any programming or math, but has earned a C or better in English. 9 out of 10 will get the same answer and that is the same as mine. This is how we know that my interpretation is correct. Just find and ask 10 kids. >Whatever your answer is, you will have a job finding it in the actual >normative text, even for C++, and the informative text does not help. The job was trivial. That most trivial question I've been asked in years. Indeed, so trivial, that I'd defer to a random child I met on the street. Indeed, for C, I will even remove the requirement that they even need to speak English to interpret the text for you. I only require they have an IQ of 70 or better and a translator so we can speak to them and they can speak to us. Directly stated, as quoted above. Next. And, and this hasn't changed any, and there is no controversy. I think your memory is just gone, sorry. You think things that never happened, happened. >I did my best to try to get AN answer out of WG14 during C99, and >failed dismally. Then trivially, you were were surrounded by idiots, because it's that, or no one respected you enough to directly answer your question and quote the standard for you, and offer to endlessly explain each and every word until you understood. I've started the process. Now, its your turn. Do you understand the words as quoted? Do you know what a mmeory read is? Do you know what a memory write is, do you know what 1 or more is, do you know what byte means, do you know what unspecified means? One you understand these things, I think the rest just falls out, but if not, let me know what you're stuck on and I can elaborate.