Note that there are some explanatory texts on larger screens.

plurals
  1. POUnspecified, undefined and implementation defined behavior WIKI for C
    primarykey
    data
    text
    <p>Although there is plentiful of links about this subject on SO, I think that there is something missing: a clear explanation in plain language of what are the differences between <strong>unspecified behavior</strong> (UsB), <strong>undefined behaviour</strong> (UB) and <strong>implementation-defined behavior</strong> (IDB) with detailed but easy explanation of any use-case and example.</p> <p><strong>Note:</strong> I made the <em>UsB</em> acronym up for sake of compactness in this WIKI, but don't expect to see it used elsewhere.</p> <p>I know this may seem a duplicate of other posts (the one it comes closer is <a href="https://stackoverflow.com/questions/2397984/undefined-unspecified-and-implementation-defined-behavior?rq=1">this</a>), but <strong><em>before anyone marks this as a duplicate</em></strong>, please consider what are the problems with all the material I already found (and I'm going to make a community WIKI out of this post):</p> <ul> <li><p>Too many scattered examples. Examples are not bad, of course, but sometimes one cannot find an example that nicely fits his problem at hand, so they may be confusing (especially for newbies). </p></li> <li><p>Examples are often only code with few explanations. On such delicate matters, especially for (relative) newbies, a more top-down approach could be better: first a clear, simple explanation with an abstract (but not legalistic) description, <em>then</em> some simple examples <em>with explanations on why they trigger some behavior</em>.</p></li> <li><p>Some posts often sport a mix of C and C++ examples. C and C++ sometimes are not in agreement of what they deem UsB, UB and IDB, so an example can be misleading for someone not proficient in both languages.</p></li> <li><p>When a definition of UsB, UB, and IDB is given, usually it is a plain citation of the standards, which sometimes may be unclear or too difficult to digest for newbies.</p></li> <li><p>Sometimes the citation of the standards are partial. Many posts cite the standard only for the parts that are useful for the problem at hand, which is good, but lacks generality. Moreover citation of the standards often is not accompanied by any explanation (bad for beginners).</p></li> </ul> <p>Since I am not a super-expert on this subject myself, I will make a community WIKI so that anyone interested can contribute and improve the answer.</p> <p>In order not to spoil my purpose to create a <strong>structured</strong> beginner-friendly WIKI, I'd like the posters to follow a couple of simple guidelines when editing the WIKI:</p> <ul> <li><p><strong>Categorize your use case.</strong> Try to put your example/code under an already existing category, if applicable, otherwise create a new one.</p></li> <li><p><strong>First the plain-words description.</strong> First describe with simple words (without oversimplifying, of course - quality first!) the example or the point you are trying to make. <em>Then</em> put code samples or citations.</p></li> <li><p><strong>Cite the standards by reference.</strong> Don't post snippets of various standards, but give clear references (e.g C99 WG14/N... section 1.4.7, paragraph ...) <em>and</em> post a link to the relevant resource, if possible.</p></li> <li><p><strong>Prefer free online resources.</strong> If you want to cite books or non-freely available resources that's ok (and may improve the quality of the WIKI), but try to add also some links to free resources. This is really important especially for ISO standards. You are welcome to add links to official standards, but try to add an equivalent link to freely available drafts as well. And please <strong>don't replace</strong> links to drafts with references to official standards, <strong>add to them</strong>. Even some Computer Science departments in some universities don't have a copy of the ISO standard(s), let alone most programmers at large!</p></li> <li><p><strong>Don't post code unless really necessary.</strong> Post code only if an explanation using only plain English would be awkward or unclear. Try to limit code samples to one-liners. Post links to other SO Q&amp;A instead.</p></li> <li><p><strong>Don't post C++ examples.</strong> I'd like this to become a sort of FAQ <strong><em>for C</em></strong> (If someone wants to start a twin-thread for C++ that would be great, though). Relevant differences with C++ are welcome, but only as side-notes. That is after you explain the C case thoroughly you may add a couple of statements about C++ if this would help a C programmer when switching to C++, but I wouldn't want to see examples with more than, say, 20% C++ stuff. Usually a simple note like <em>"(C++ behaves differently in this case)"</em> plus a relevant link should be enough.</p></li> </ul> <p>Since I'm fairly new to SO I hope I'm not breaking any rule by starting a Q&amp;A this way. Sorry if this is the case. The mods are welcome to let me know about it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. COThis seems a little broad for SO. However, relevant to your question, I once stumbled upon this list which is interesting: https://www.securecoding.cert.org/confluence/display/seccode/CC.+Undefined+Behavior
      singulars
    2. COSo you have diagnosed a lack of three definitions that would take ten lines at most (if they are indeed missing. I seem to have seen them several times), and your solution to that problem is three screens of, for lack of a better phrase, terms of services about how to edit an entry that you have opened on a site that is not really a wiki? And the reason you introduce acronyms that nobody else uses is to make it simpler for beginners, too?
      singulars
    3. CO@Pascal Please reread my post. I **never** said I diagnosed a lack of definitions tout-court. I tried to explain that I found too many sources of information on the subject, but they lacked organization and sometimes the definitions were a bit too technical for newbies. As for the fact this is not a WIKI, well I may have misunderstood the feature, but when I see the term "WIKI" I think it is to be used as a WIKI, and I wrote a WIKI posts. If SO wiki is not really a wiki feature, well sorry for the misunderstanding, but anyone then can propose to close this post.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload