Re: [TYPES] Declarative vs imperative

Uday S Reddy <[email protected]>
Newsgroups gmane.comp.science.types
Message-ID <[email protected]>
[ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list ]

Robbert Krebbers writes:

> Let me then notice that in the case of C, it is worse than just 
> non-determinism. 

I do not believe that "non-determinism" is the right take on it.  C was
designed to be a deterministic programming language, at least in its
sequential programming fragment, but various aspects of behaviour are left
"undefined" or "unspecified".  So, the programmer is required to avoid all
the undefined/unspecified aspects of behaviour.  Any apparent
non-determinism in a C program constitutes a programming bug.

For people that think that a compiler determines the language rather than
the language definition, this might come as a huge shock.  That is
precisely how I intended it to be.

> There are also so called sequence point violations, 
> which happen if you modify an object more than once (or read after 
> you've modified it) in between two sequence points. For example
> 
>    int x = 0;
>    int main() {
>      printf("%d ", (x = 3) + (x = 4));
>      printf("%d\n", x);
>      return 0;
>    }
> 
> not just randomly prints "7 3" or "7 4", but instead gives rise to 
> undefined behavior, and could print arbitrary nonsense.

So, when the C definition tells you that "x = 3" is an "expression" rather
than a "statement", it is a huge lie.  Expressions are not supposed to
change the state, despite the fact that a lot of library functions of C do
precisely that.

Those of us that stopped teaching C in our undergraduate curricula did so
for very good reasons.

Cheers,
Uday
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.