Criticism of the C programming language: Difference between revisions

Content deleted Content added
Line 40:
==Undefined behaviour==
 
Many operations in C that have [[undefined behavior]] are not required to be diagnosed at [[compile time]]. In the case of C, "undefined behavior" means that the exact behavior which arises is not specified by the standard, and exactly what will happen does not have to be documented by the C implementation. A famous, although misleading, expression in the [[newsgroup]]s [news:comp.std.c comp.std.c] and [news:comp.lang.c comp.lang.c] is that the program could cause "[[Nasal demons|demons to fly out of your nose]]".<ref>{{cite web | url=http://www.catb.org/jargon/html/N/nasal-demons.html | title=Jargon File entry for ''nasal demons'' }}</ref> Sometimes in practice what happens for an instance of undefined behavior is a [[software bug|bug]] that is hard to track down and which may corrupt the contents of memory. Sometimes a particular compiler generates well-behaved actions that are not the same as would be obtained using a different C compiler. The reason some behavior has been left undefined is to allow the compiler to generate more efficient executable code for well-defined behavior, which was deemed important for C's primary role as a systems implementation language; it is the programmer's responsibility to avoid undefined behavior. Examples of undefined behavior are:
 
* accessing outside the bounds of an array