LWN.net Logo

What Every C Programmer Should Know About Undefined Behavior #3/3

What Every C Programmer Should Know About Undefined Behavior #3/3

Posted May 23, 2011 19:45 UTC (Mon) by kripkenstein (subscriber, #43281)
In reply to: What Every C Programmer Should Know About Undefined Behavior #3/3 by cesarb
Parent article: What Every C Programmer Should Know About Undefined Behavior #3/3

> There is at least one processor architecture [ia64] where accessing uninitialized variables can crash your program. It is not the compiler in this case, it is the processor itself which has a special "undefined" value.

Somewhat similar: If you consider JavaScript an 'architecture', then when compiling C or C++ to JS (using Emscripten), reading uninitialized values gives you a JS 'undefined' value, which isn't a number (since you are doing something like x = [1,2,3]; y = x[100]. So y will be undefined).

This doesn't crash, but it can lead to very unpredictable behavior. For example, reading such a value into x, then x+0 != x (since undefined+0 = NaN, and NaN != undefined).


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds