473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Behaviour question

AFAIK the C standard divides behaviour of different things into four
classes.
1) Defined behaviour. The implementation must do exactly what the
standard says.
2) Implementation-defined behaviour. The implementation must choose some
behaviour, document it, and be consistent about it.
3) Unspecified behaviour. The implementation must pick one of several
possible behaviours, but does not need to be consistent about it.
4) Undefined behaviour. The implementation can do anything it wants to.

Now, let's call the things that cause defined behaviour I, the things
that cause implementation-defined behaviour II, the things that cause
unspecified behaviour III, and the things that cause undefined behaviour
IV.

AFAIK, the compiler is allowed to do any one, or none, of the following:
1) Act as if the C standard defined a strictly set behaviour for I, II,
III and IV.
2) Act as if the C standard defined a strictly set behaviour for I, and
required that the implementation must choose a documented, consistent
behaviour for II, III and IV.
3) Act as if the C standard defined a strictly set behaviour for I,
required that the implementation must choose a documented, consistent
behaviour for II, and required that the implementation must pick one of
several behaviours (but not necessarily consistently) for III and IV.

In other words, this translates to:
1) Act as if everything was defined behaviour.
2) Act as if I was defined behaviour and II, III and IV were
implementation-defined behaviour.
3) Act as if I was defined behaviour, II was implementation-defined
behaviour, and III and IV were unspecified behaviour.

So therefore, if we consider the space of things the standard allows
the implementation to do, defined behaviour is a proper subset of
implementation-defined behaviour, which is a proper subset of
unspecified behaviour, which is a proper subset of undefined behaviour.

For example, painting your house pink is in the set-wise difference
of undefined and unspecified behaviour, and returning 1 from a function
when the program is run once, but returning 2 when it is run again,
without any change in the environment, is in the set-wise difference
of unspecified and implementation-defined behaviour.

Is the above correct? I'd appreciate some sort of in-depth critique.
Thanks.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"How can we possibly use sex to get what we want? Sex IS what we want."
- Dr. Frasier Crane
Nov 13 '05 #1
2 2906
Joona I Palaste wrote:
So therefore, if we consider the space of things the standard allows
the implementation to do, defined behaviour is a proper subset of
implementation-defined behaviour, which is a proper subset of
unspecified behaviour, which is a proper subset of undefined behaviour.
No. Defined behaviour is /not a subset/ of implementation defined
behaviour. The behaviour is /either/ (standard-)defined /or/
implementation-defined. If something is (standard-)defined the
implementation is not allowed to define a different behaviour, therefor it
is not part of the implementation-defined domain.

Concerning the other kinds of behaviour, I am not so sure. Nevertheless,
personally I do not write code which uses any not (standard-)defined
behaviour.
For example, painting your house pink is in the set-wise difference
of undefined and unspecified behaviour, and returning 1 from a function
when the program is run once, but returning 2 when it is run again,
without any change in the environment, is in the set-wise difference
of unspecified and implementation-defined behaviour.


Pardon?

/Sven

--
Sven Semmler http://www.semmlerconsulting.com/
GPG Fingerprint: 72CA E26D C2A3 1FEB 7AFC 10EA F769 A9A4 937F 5E67
Nov 13 '05 #2
Joona I Palaste wrote:
[...]
So therefore, if we consider the space of things the standard allows
the implementation to do, defined behaviour is a proper subset of
implementation-defined behaviour, which is a proper subset of
unspecified behaviour, which is a proper subset of undefined behaviour.

For example, painting your house pink is in the set-wise difference
of undefined and unspecified behaviour, and returning 1 from a function
when the program is run once, but returning 2 when it is run again,
without any change in the environment, is in the set-wise difference
of unspecified and implementation-defined behaviour.

Is the above correct? I'd appreciate some sort of in-depth critique.
Thanks.


I'm not entirely sure I understand where you're heading
with this, so my comments may be wide of the mark. If so,
please be forgiving ...

When you write of "behavior," you seem to concentrate on
the "observed outcome:" painting the house pink, or returning
this or that value. However, an outcome in and of itself is
not (in general) categorizable as defined, implementation-
defined, unspecified, or undefined. One must consider the
stimulus, the circumstances that produce the outcome. The
fact that a function returns 1 on the first invocation and 2
the next could be an example of *any* of your four classes of
behavior:

int defined(void) {
static int x;
return ++x;
}

int implementation_defined(void) {
static int x;
return x += sizeof(short);
}

int unspecified(void) {
static int x;
return x += ("o" == "hello" + 4);
}

int undefined(void) {
auto int x;
return x;
}

I think the attempt to categorize outcomes as "defined"
and so forth is backwards: the Standard actually describes
particular *circumstances* as producing various outcomes.
Some stimuli produce fully-specified outcomes, some produce
completely unrestricted outcomes, some are in between. The
color of your house is not a matter addressed by the Standard,
so we can infer that if a program paints your house pink it
can only be by virtue of invoking undefined behavior: that is,
of allowing circumstances to develop in such a way that the
Standard no longer governs the outcome. But for many other
outcomes it is not possible to reason backwards in this way.

--
Er*********@sun.com
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Plumer | last post by:
Hello everyone, I am using MS .NET Framework 1.0 Version 1.0.3705 developing a C# client application using SQL Server on the server side. I am looking to implement drag & drop in a TreeView...
4
by: Mark Stijnman | last post by:
A while ago I posted a question about how to get operator behave differently for reading and writing. I basically wanted to make a vector that can be queried about whether it is modified recently...
5
by: Sumeet | last post by:
I met a question in a test which invoked undefined behaviour and i was asked to answer the Expected answer of the question Specifications := Win98 Os Tc compiler int i=23; i=(i++|++i)^(i++ +...
8
by: Joona I Palaste | last post by:
We all know that this: void *p; if (p=malloc(1)) { free(p); p; } causes undefined behaviour if malloc() succeeds. But what about this?
25
by: Nitin Bhardwaj | last post by:
Well, i'm a relatively new into C( strictly speaking : well i'm a student and have been doing & studying C programming for the last 4 years).....and also a regular reader of "comp.lang.c" I...
31
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
285
by: Sheth Raxit | last post by:
Machine 1 : bash-3.00$ uname -a SunOS <hostname5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R bash-3.00$ gcc -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/...
10
by: cjard | last post by:
I have a client and server that enjoy the following simple dialogue: Client connects Client sends request Server sends response Client disconnects This is the way it must be. The response...
3
by: Walter Cruz | last post by:
Hi all! Just a simple question about the behaviour of a regex in python. (I discussed this on IRC, and they suggest me to post here). I tried to split the string "walter ' cruz" using \b . ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.