Re: [TYPES] Declarative vs imperative

Tjark Weber <[email protected]>
Newsgroups gmane.comp.science.types
Message-ID <1366797476.1748.19.camel@weber>
[ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list ]

Mark,

On Tue, 2013-04-23 at 09:49 -0700, Mark Janssen wrote:
> > Well, the C standard does not fully define the meaning of all C
> > programs, e.g. when a program divides by zero. The actual program
> > output may depend on the compiler options. The machine code is
> > usually strictly defined, so in a sense the C compiler fills in
> > gaps.
> 
> Right, re: division by zero, but the program output is still
> deterministic -- the gap was filled before you even wrote your
> program, by the compiler vendor/writer.  A given compiler (say  gcc
> vs. TurboC) could handle the case of division by zero differently, but
> the compiler writer still has to make the design decision what his/her
> compiler will do.  Once that decision is made, it will do the same
> thing every time.  *There is no ambiguity, the gap was filled by the
> compiler designer *prior* to your code.*

What you describe here is called *implementation-defined behavior* in
the C standard. There is quite a list of things that are
implementation-defined, see, e.g.,
http://gcc.gnu.org/onlinedocs/gcc/C-Implementation.html

In contrast, division by 0 causes *undefined behavior* according to the
C standard. This is a quite different category that gives you no
guarantees about your program's behavior whatsoever. Your compiler
might very well do one thing today and another tomorrow.

Best,
Tjark
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.