B
Billy Bong
If you hang around this newsgroup enough, you'll soon find out that one
of the most insidious crimes you can commit in the C language is
undefined behavior.
What is undefined behavior?
According to the C Standard:
"behavior, upon use of a nonportable or erroneous program construct or of
erroneous data, for which this International Standard imposes no
requirements"
One of the many popular consequences of undefined behavior purported in
this newsgroup is that *anything* can happen. For example, the following
post, from an arguably c.l.c regular, apparently claims that undefined
behavior could start WWIII:
http://groups.google.com/group/comp.lang.c/browse_thread/
thread/3686f35c51a00ce5/a452e5db10ca8f52?lnk=st&q=#a452e5db10ca8f52
Claiming that undefined behavior can start WWIII is not something to be
taken lightly. Especially in light of the fact that the Linux Kernel
Source commits undefined behavior.
Here is what the C Standard has to say about one aspect of undefined
behavior (section numbers are from the C99 Standard, and may differ from
the C90 Standard, but the wording in the two standards is effectively the
same):
In Section 7.1.3 (Reserved identifiers) of the C Standard, it states the
following:
"All identifiers that begin with an underscore and either an uppercase
letter or another underscore are always reserved for any use."
In Appendix J.2 (Undefined behavior) of the C Standard, it states the
following:
"The program declares or defines a reserved identifier, other than as
allowed by 7.1.4 (7.1.3)."
(Note that section 7.1.4 (Library functions), as specified above, is
immaterial to the discussion at hand.)
And, here are some facts ...
1. The Linux Kernel Source is NOT part of the implementation, and is
therefore NOT allowed to define any reserved identifiers as specified by
the C Standard.
2. The Linux Kernel Source defines identifiers that begin with a leading
underscore followed by an uppercase letter, in almost all of its header
files. For example, the file fs.h starts off with this:
#ifndef _LINUX_FS_H
#define _LINUX_FS_H
3. The Linux Kernel Source, as a result, commits undefined behavior.
If you follow all of this, like you should, and you believe what many in
this newsgroup purport to be the consequences of undefined behavior, then
you owe it to yourself to seriously consider the ramifications of
undefined behavior, any time you run Linux.
Personally, I *do* buy into this whole undefined behavior thing, though
not necessarily to the extent that some of the extremists here in this
group seem to purport. And my buy-in is based on experience, as I'll now
describe.
Sometimes, when I boot into Linux, one of my monitors does not display
anything. When this happens, I immediately reboot into Windows XP, to see
if it's a software or a hardware problem. And--100% of the time--the
monitor comes up as expected in Windows XP. I then reboot into Linux,
and, most of the time, the monitor comes up as expected. I attribute this
behavior to undefined behavior in Linux, and sometimes wonder if it's the
result of the undefined behavior that results from using the above
mentioned reserved identifiers (or perhaps due to the "kludges" and
"fixmes" so ubiquitously found in The Linux kernel Source).
There are other things that I experience with Linux that I don't
experience with Windows, and I attribute these behaviors to the undefined
behavior in Linux. For example, I have an external USB drive that has one
Linux partition and one NTFS partition. Sometimes (a lot of times
recently) when I have this drive plugged in, the mouse cursor freezes for
about 5 seconds, and then unfreezes for about 760 milliseconds. This
behavior periodically repeats, over and over (in other words, cursor
freezes, then unfreezes, then freezes, then unfreezes, etc.). I do not
experience this problem when I boot into Windows XP. I attribute this
behavior to undefined behavior, as defined by the C Standard, and as you
have all taught me so well.
Thanks all for teaching me so well about undefined behavior.
of the most insidious crimes you can commit in the C language is
undefined behavior.
What is undefined behavior?
According to the C Standard:
"behavior, upon use of a nonportable or erroneous program construct or of
erroneous data, for which this International Standard imposes no
requirements"
One of the many popular consequences of undefined behavior purported in
this newsgroup is that *anything* can happen. For example, the following
post, from an arguably c.l.c regular, apparently claims that undefined
behavior could start WWIII:
http://groups.google.com/group/comp.lang.c/browse_thread/
thread/3686f35c51a00ce5/a452e5db10ca8f52?lnk=st&q=#a452e5db10ca8f52
Claiming that undefined behavior can start WWIII is not something to be
taken lightly. Especially in light of the fact that the Linux Kernel
Source commits undefined behavior.
Here is what the C Standard has to say about one aspect of undefined
behavior (section numbers are from the C99 Standard, and may differ from
the C90 Standard, but the wording in the two standards is effectively the
same):
In Section 7.1.3 (Reserved identifiers) of the C Standard, it states the
following:
"All identifiers that begin with an underscore and either an uppercase
letter or another underscore are always reserved for any use."
In Appendix J.2 (Undefined behavior) of the C Standard, it states the
following:
"The program declares or defines a reserved identifier, other than as
allowed by 7.1.4 (7.1.3)."
(Note that section 7.1.4 (Library functions), as specified above, is
immaterial to the discussion at hand.)
And, here are some facts ...
1. The Linux Kernel Source is NOT part of the implementation, and is
therefore NOT allowed to define any reserved identifiers as specified by
the C Standard.
2. The Linux Kernel Source defines identifiers that begin with a leading
underscore followed by an uppercase letter, in almost all of its header
files. For example, the file fs.h starts off with this:
#ifndef _LINUX_FS_H
#define _LINUX_FS_H
3. The Linux Kernel Source, as a result, commits undefined behavior.
If you follow all of this, like you should, and you believe what many in
this newsgroup purport to be the consequences of undefined behavior, then
you owe it to yourself to seriously consider the ramifications of
undefined behavior, any time you run Linux.
Personally, I *do* buy into this whole undefined behavior thing, though
not necessarily to the extent that some of the extremists here in this
group seem to purport. And my buy-in is based on experience, as I'll now
describe.
Sometimes, when I boot into Linux, one of my monitors does not display
anything. When this happens, I immediately reboot into Windows XP, to see
if it's a software or a hardware problem. And--100% of the time--the
monitor comes up as expected in Windows XP. I then reboot into Linux,
and, most of the time, the monitor comes up as expected. I attribute this
behavior to undefined behavior in Linux, and sometimes wonder if it's the
result of the undefined behavior that results from using the above
mentioned reserved identifiers (or perhaps due to the "kludges" and
"fixmes" so ubiquitously found in The Linux kernel Source).
There are other things that I experience with Linux that I don't
experience with Windows, and I attribute these behaviors to the undefined
behavior in Linux. For example, I have an external USB drive that has one
Linux partition and one NTFS partition. Sometimes (a lot of times
recently) when I have this drive plugged in, the mouse cursor freezes for
about 5 seconds, and then unfreezes for about 760 milliseconds. This
behavior periodically repeats, over and over (in other words, cursor
freezes, then unfreezes, then freezes, then unfreezes, etc.). I do not
experience this problem when I boot into Windows XP. I attribute this
behavior to undefined behavior, as defined by the C Standard, and as you
have all taught me so well.
Thanks all for teaching me so well about undefined behavior.