3 ms·
That was obviously a typo. C'mon.
by spacechild1 3y ago
That was obviously a typo. C'mon.
- kazinator 3y agoI don't follow. What is a typo? Whose typo? I see that exact text as far back as C99 (in 4 Conformance) "A program that is correct in all other aspects, operating on correct data, containing unspecified behavior shall be a correct program and act in accordance with 5.1.2.3."
- spacechild1 3y ago> I don't follow. What is a typo? Whose typo? My second paragraph did contain a typo ("unspecified" instead of "undefined") which I have fixed (see EDIT). > "A program that is correct in all other aspects, operating on correct data, containing unspecified behavior shall be a correct program and act in accordance with 5.1.2.3." In conjuction with the preceding passage about undefined behavior, I read this as follows: Any program that does not violate ‘‘shall’’ or ‘‘shall not’’ requirements, does not contain undefined behavior and operates on correct data is a correct program; it may, however, contain unspecified behavior. How would you read this instead? Back to 4 ("Conformance"): > [...] Undefined behavior is otherwise indicated in this International Standard by the words ‘‘undefined behavior’’ or by the omission of any explicit definition of behavior. [...] What is an explicit definition? It just isn't possible to completely define any phenomenon down to the smallest detail, so one can always come up with a case that isn't "explicitly defined". IMHO this passage is a mistake in the standard.
- kazinator 3y agoThe purpose of that sentence is not entirely clear to me. It seems to be defining the term "correct program", but hasn't given the term in italics, and the term is not used anywhere. Most C programs contain unspecified behavior because, for example, the order of evaluation of function arguments is unspecified. If we call any function of two or more arguments, unspecified behavior has occurred. Usually, there is no visible difference, so it doesn't matter. It's not clear to me why that sentence includes unspecified behavior, but not implementation-defined. I think it may be intended to include implementation-defined, since implementation-defined behavior is "unspecified behavior where each implementation documents how the choice is made". In any case, it's saying that nonportable programs can be correct. Later in another paragraph, a strictly-conforming program concept is defined which cannot produce output dependent on implementation-defined or unspecified behavior. Those behaviors themselves cannot be eliminated (like unspecified evaluation orders) but the program doesn't produce any output dependent on them. Note that although #include <unistd.h> is defined by implementations, it is not "implementation-defined behavior". It is a documented extension. The same section talks about extensions a little down "A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any strictly conforming program." An explicit definition is where the standard gives a requirement in words. I think the word "explicit" is there just for emphasis. Definitions are explicit. Explicit is the opposite of implicit; implicit means understood without words. You can't define something without words. Maybe the purpose is to discourage implementors and users from making tenuous inferences of unwritten definitions of behavior.