In the context of the comp.lang.c newsgroup,
the term "undefined behavior" actually refers to
behavior not defined by the ANSI/ISO C [89]9 standard.
Specifically, it is *not* true that "anything can happen"
if your C code invokes "undefined behavior".
Behavior not defined by the ANSI/ISO C [89]9 standard
may be defined by some other standard (i.e. POSIX) or
it may be defined by [the implementation of] your compiler,
your operating system or your machine architecture.
There exists *no* combination of the above
in which behavior is not defined.
Behavior may be "undocument ed" or documentation may be "unpublishe d".
Sometimes, this is because of an oversight on the part of
the respective developers but, more often, documentation
of non-standard "features" simply isn't offered to the public
because the developer cannot promise to support the "features".
There has never been a credible report of
demons flying up any programmer's nose
because he [or she] invoked "undefined behavior". 19 2579
On Sat, 10 Jan 2004 18:14:04 -0800, "E. Robert Tisdale"
<E.************ **@jpl.nasa.gov > wrote in comp.lang.c: In the context of the comp.lang.c newsgroup, the term "undefined behavior" actually refers to behavior not defined by the ANSI/ISO C [89]9 standard. Specifically, it is *not* true that "anything can happen" if your C code invokes "undefined behavior".
Wrong again, dipstick.
The term "undefined behavior" is precisely defined in the C standard
itself, so therefore it has a precise meaning in the C language and
the comp.lang.c newsgroup.
Paragraph 3 of section 3.4.3 states:
"undefined behavior
behavior, upon use of a nonportable or erroneous program construct or
of erroneous data, for which this International Standard imposes no
requirements"
Notice the key phrase "imposes no requirements". In small words, that
means that if your program produces undefined behavior, anything at
all that happens is just as valid or invalid as anything else, as far
as the standard C language is concerned.
Behavior not defined by the ANSI/ISO C [89]9 standard may be defined by some other standard (i.e. POSIX) or it may be defined by [the implementation of] your compiler, your operating system or your machine architecture. There exists *no* combination of the above in which behavior is not defined.
Of course this as absurd. There are circumstances under which the
behavior is undefined because it is just plain unknowable and
unpredictable until the actual instant of execution, each and every
time the code is executed.
And of course, there is no such thing as a POSIX standard as far as
this group is concerned.
Behavior may be "undocument ed" or documentation may be "unpublishe d". Sometimes, this is because of an oversight on the part of the respective developers but, more often, documentation of non-standard "features" simply isn't offered to the public because the developer cannot promise to support the "features".
There has never been a credible report of demons flying up any programmer's nose because he [or she] invoked "undefined behavior".
No, but there have been cases of hard disk drive reformatting.
Jumping to an indeterminate pointer on an IBM XT could well result in
invoking the ROM hard disk format routine.
Tell me how defined the behavior of this program is:
#include <time.h>
#include <stdio.h>
int main(void)
{
double *dp = (double *)time(0);
printf("The value is %f\n", *dp);
return 0;
}
Now just what document tells me whether this program will be shut down
for a memory access violation, a memory alignment fault, a floating
point hardware exception, or will happen to output some gibberish?
And what guarantees that the result will be the same if I run the same
program tomorrow, next week, next month, next year?
The possible non-standard definitions of what might happen when
undefined behavior is invoked is just plain irrelevant -- and
off-topic -- here.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > writes: There has never been a credible report of demons flying up any programmer's nose because he [or she] invoked "undefined behavior".
Irrelevant, as nobody claims otherwise.
OTOH, the often heard claim that if a C program invoked undefined
behavior, a conforming C implementation would be allowed to make
demons fly out of the programmer's nose, is definitely true. This
follows directly from 3.4.3#1.
Martin
In article <40************ **@jpl.nasa.gov >,
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote: There has never been a credible report of demons flying up any programmer's nose because he [or she] invoked "undefined behavior".
There have been multiple credible reports of harddisks being reformatted
because a programmer invoked "undefined behavior". Actually, upon closer
examination, _every single case_ of a harddisk being reformatted by a C
program involved "undefined behavior".
E. Robert Tisdale wrote: In the context of the comp.lang.c newsgroup, the term "undefined behavior" actually refers to behavior not defined by the ANSI/ISO C [89]9 standard. Specifically, it is *not* true that "anything can happen" if your C code invokes "undefined behavior".
Behavior not defined by the ANSI/ISO C [89]9 standard may be defined by some other standard (i.e. POSIX) or it may be defined by [the implementation of] your compiler, your operating system or your machine architecture. There exists *no* combination of the above in which behavior is not defined.
Behavior may be "undocument ed" or documentation may be "unpublishe d". Sometimes, this is because of an oversight on the part of the respective developers but, more often, documentation of non-standard "features" simply isn't offered to the public because the developer cannot promise to support the "features".
Why did you bother to write this? You cannot be that clueless. The
Standard defines the behaviour of certain program constructs on valid
data. Anything else is "undefined behaviour".
There has never been a credible report of demons flying up any programmer's nose because he [or she] invoked "undefined behavior".
No. The demons fly out from your nose. Not credible? If you can't
believe Kaz, who's left? :-)
--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
On Sun, 11 Jan 2004, Christian Bau wrote: "E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote: There has never been a credible report of demons flying up any programmer's nose because he [or she] invoked "undefined behavior".
There have been multiple credible reports of harddisks being reformatted because a programmer invoked "undefined behavior". Actually, upon closer examination, _every single case_ of a harddisk being reformatted by a C program involved "undefined behavior".
Wrong. The behavior that led to the harddisk-reformatting might
instead have been implementation-defined; for example, the
behavior upon signed integer truncation.
"I assigned 0xFF to a 'char' and demons flew out of my nose!
Luckily, I had read the manual and was expecting it."
--Zak
-Arthur
Joe Wright wrote: E. Robert Tisdale wrote:
.... snipped garbage ... Why did you bother to write this? You cannot be that clueless.
You are talking about E.R. Trollsdale here. He has climbed far
greater heights in the past; this is completely innocuous in
comparison.
--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Christian Bau wrote: E. Robert Tisdale wrote:
There has never been a credible report of demons flying up any programmer's nose because he [or she] invoked "undefined behavior".
There have been multiple credible reports of hard disks being reformatted because a programmer invoked "undefined behavior". Actually, upon closer examination, _every single case_ of a hard disk being reformatted by a C program involved "undefined behavior".
I don't think that it is possible to write a C program
to reformat a hard disk drive without invoking behavior
not defined by the ANSI/ISO C[89]9 standard.
Jack Klein wrote: E. Robert Tisdale wrote:
In the context of the comp.lang.c newsgroup, the term "undefined behavior" actually refers to behavior not defined by the ANSI/ISO C [89]9 standard. Specificall y, it is *not* true that "anything can happen" if your C code invokes "undefined behavior". The term "undefined behavior" is precisely defined in the C standard itself, so therefore it has a precise meaning in the C language and the comp.lang.c newsgroup.
Paragraph 3 of section 3.4.3 states:
"undefined behavior behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements"
Isn't that exactly what I said above?
Notice the key phrase "imposes no requirements". In small words, that means that, if your program produces undefined behavior, anything at all that happens is just as valid or invalid as anything else as far as the standard C language is concerned.
No. The phrase "imposes no requirements" means exactly that.
Not even that "anything at all that happens
is just as valid or invalid as anything else".
It means that what happens is left up to the compiler developer. Behavior not defined by the ANSI/ISO C [89]9 standard may be defined by some other standard (i.e. POSIX) or it may be defined by [the implementation of] your compiler, your operating system or your machine architecture. There exists *no* combination of the above in which behavior is not defined.
There are circumstances under which the behavior is undefined because it is just plain unknowable and unpredictable until the actual instant of execution, each and every time the code is executed.
Where is it written that unpredictable behavior is undefined behavior?
And of course, there is no such thing as a POSIX standard as far as this group is concerned.
Nonsense!
The POSIX standard exists independent of
whether or not it is off-topic in any usenet newsgroup
unless you are a member of the Flat Earth Society: http://www.flat-earth.org/ Behavior may be "undocument ed" or documentation may be "unpublishe d". Sometimes, this is because of an oversight on the part of the respective developers but, more often, documentation of non-standard "features" simply isn't offered to the public because the developer cannot promise to support the "features".
There has never been a credible report of demons flying up any programmer's nose because he [or she] invoked "undefined behavior".
No, but there have been cases of hard disk drive reformatting. Jumping to an indeterminate pointer on an IBM XT could well result in invoking the ROM hard disk format routine.
Tell me how defined the behavior of this program is:
#include <time.h> #include <stdio.h>
int main(int argc, char* argv[]) { double* dp = (double*)time(0 ); printf("The value is %f\n", *dp); return 0; }
Now just what document tells me whether this program will be shut down for a memory access violation, a memory alignment fault, a floating point hardware exception, or will happen to output some gibberish? And what guarantees that the result will be the same if I run the same program tomorrow, next week, next month, next year?
The possible non-standard definitions of what might happen when undefined behavior is invoked is just plain irrelevant -- and off-topic -- here.
I am appalled by your misunderstandin g of "undefined behavior".
How did you know that it could "shut down" due to
a memory access violation, a memory alignment fault,
a floating-point hardware exception or output some gibberish?
Evidently, you are aware that the behavior of this program
is *well* defined -- it's simply not predictable
because you don't have easy access to all of the information
that would be required to predict what will happen.
But, given that your platform is deterministic,
it is, in principle, *always* possible to predict
what this program will do each time that you run it.
But what I really want to know is,
"Did demons ever fly up your nose when you ran this program?" ;-)
"E. Robert Tisdale" wrote: Christian Bau wrote: E. Robert Tisdale wrote:
There has never been a credible report of demons flying up any programmer's nose because he [or she] invoked "undefined behavior".
There have been multiple credible reports of hard disks being reformatted because a programmer invoked "undefined behavior". Actually, upon closer examination, _every single case_ of a hard disk being reformatted by a C program involved "undefined behavior".
I don't think that it is possible to write a C program to reformat a hard disk drive without invoking behavior not defined by the ANSI/ISO C[89]9 standard.
Very good. Direct contradiction with your own quote above.
Logic, thy name is Trollsdale.
--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mantorok Redgormor |
last post by:
If I do something like the following:
unsigned int bar=10;
Then use, -bar with the unary '-' and assign this value to an int,
does this invoke undefined behavior in anyway?
Basically I have:
unsigned int bar=10;
int foo;
|
by: Mantorok Redgormor |
last post by:
#include <stdio.h>
struct foo { int example; struct bar *ptr; };
int main(void)
{
struct foo baz;
baz.ptr = NULL; /* Undefined behavior? */
return 0;
|
by: jimjim |
last post by:
Hello,
#include <stdio.h>
int main(int argc, char *argv)
{
int x = 1;
printf("%d %d %d\n", ++x, x, x++);
return 0;
}
|
by: dragoncoder |
last post by:
Hi all,
Does the following code invoke undefined behaviour ?
$ cat a1.cc
#include <iostream>
#include <limits>
int main() {
int a = INT_MAX/2;
|
by: Rajesh S R |
last post by:
Can anyone tell me what is the difference between undefined behavior
and unspecified behavior?
Though I've read what is given about them, in ISO standards, I'm still
not able to get the difference.
For example:
Consider the following code:
a = i;
We say that the above expression statement produces undefined
| |
by: Franz Hose |
last post by:
the following program, when compiled with gcc and '-std=c99', gcc says
test.c:6: error: jump into scope of identifier with
variably modified type
that is, it does not even compile.
lcc-win32, on the other hand, reports
Warning test.c: 7 unreachable code
|
by: Kenny McCormack |
last post by:
#include <stdio.h>
int main(void) { printf("hello, world\n"); }
I compile it with all warning turned on and it still works fine.
|
by: jl_post |
last post by:
Hi,
I've heard that if you've declared a variable (such as a double or
an int) and not initialize it, then the result of printing out its
value is undefined.
I've also heard that "undefined behavior" can mean just about
anything, such as "flying monkeys shooting out of your nose." Sure,
that's an exaggeration, but normally I interpret that to mean that the
program can crash (or cease running) erratically, or even corrupt
|
by: blargg |
last post by:
Does ~0 yield undefined behavior? C++03 section 5 paragraph 5 seems to
suggest so:
The description of unary ~ (C++03 section 5.3.1 paragraph 8):
But perhaps "one's complement" means the value that type would have with
all bits inverted, rather than the mathematical result of inverting all
bits in the binary representation. For example, on a machine with 32-bit
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |