9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Brantley Coile <brantleycoile@me.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] Undefined Behaviour in C
Date: Mon, 23 Nov 2015 06:50:08 -0500	[thread overview]
Message-ID: <6B7DA7E3-3917-4A67-9084-1B5DD90D97F9@me.com> (raw)
In-Reply-To: <1448274004.1751482.447419065.2BE466C4@webmail.messagingengine.com>

This is an interesting issue to me because I'm becoming more and more aware of a fundamental misunderstanding of C which will make it difficult for people to write efficient code in the future. These two documents show a lack of understanding regarding the reason for undefined behavior and a confusion between undefined specification and undefined behavior. 

Efficiency is the reason for undefined specification. The objective of C was to replace assembler language without giving up the ability to write tight, efficient programs. Other languages, such as ALGOL, had defined all the behavior to great detail and as a result was very inefficient on some architectures. C avoided these inefficiencies by letting the machine do what was natural. Loading a character into an integer register is an example. It is undefined in C whether or not it sign extends or not. Some machines do it one way, some another. To force the language to one behavior requires more code on some architectures. 

Leaving these aspects to the local machine was one of the places where Dennis' genius shows through. And it's why they could write and operating system in C and have it run quite well on a tiny minicomputer while Multics with its PL/1 language was dog slow on a huge expensive mainframe. (Okay, it's only one reason.)

Ken's compiler does the right amount of optimizations, limiting them mostly to what the programmer can't fix. The idea that a C compiler can be smarter than a sloppy programmer is causing compilers to be unusable for what I do. These bloated compilers  can never be idiot proof because idiots are so ingenious. The beauty of C is that one can write a simple compiler and create very fast code by being a good programmer. Give me smart programmers and simple compilers and not dumber programmers and idiot savant, and bloat, compilers. 

So C, as it is now defined, is in no need of fixing.

The MIT paper has a confusion between the undefined specification and undefined behavior. If you load a character into an integer, sign behavior is unspecified. But how many people program 8086 large model code any more, the reason for the comment into the standard? I

'm not an expert on gcc, in fact I know more that I really want to about it. But, if it tosses code like buf + len < size, because it might be wrong on some other architecture, it's broke. 

To write fast code one need a simple notation and a simple predictable compiler. Ken's C compiler fits this requirement to a tee. 

Sent from my iPad

> On Nov 23, 2015, at 5:20 AM, Ramakrishnan Muthukrishnan <ram@rkrishnan.org> wrote:
> 
> Had been reading the SOSP paper:
> <https://pdos.csail.mit.edu/papers/stack:sosp13.pdf>
> 
> and this blog post that proposes a simpler C:
> <http://blog.regehr.org/archives/1180>
> 
> I wonder how Plan 9 C compiler, which is a non-ANSI compliant compiler,
> treats those parts that the ANSI C standard treats as undefined.
> 
> -- 
>  Ramakrishnan
> 



  parent reply	other threads:[~2015-11-23 11:50 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-23 10:20 Ramakrishnan Muthukrishnan
2015-11-23 11:20 ` Vasudev Kamath
2015-11-25 10:27   ` Alexandru Gheorghe
2015-11-25 10:43     ` Brantley Coile
2015-11-25 10:53       ` Brantley Coile
2015-11-25 12:59       ` Charles Forsyth
2015-11-25 13:48         ` erik quanstrom
2015-11-25 14:25           ` Brantley Coile
2015-11-25 14:31             ` Brantley Coile
2015-11-25 16:03             ` plannine
2015-11-25 17:13               ` Ryan Gonzalez
2015-11-25 18:41                 ` Brantley Coile
2015-11-26  2:04                   ` Prof Brucee
2015-11-26  2:43                     ` Brantley Coile
2015-11-26  2:57                       ` Prof Brucee
2015-11-26  3:48                         ` Ryan Gonzalez
2015-11-26  7:27                     ` Bakul Shah
2015-11-26 11:22                       ` Brantley Coile
2015-11-26 11:37                         ` tlaronde
2015-11-26 11:55                           ` Charles Forsyth
2015-11-26 11:38                         ` Bruce Ellis
2015-11-26 16:31                         ` erik quanstrom
2015-11-26 16:42                           ` Brantley Coile
2015-11-26 16:50                             ` Charles Forsyth
2015-11-26 17:12                               ` erik quanstrom
2015-11-26 16:46                           ` Alexandru Gheorghe
2015-11-26 17:48                         ` Bakul Shah
2015-11-26 18:04                           ` Brantley Coile
2015-11-26 23:14                           ` Steve Simon
2015-11-26 23:24                             ` Charles Forsyth
2015-11-26 23:55                             ` Brantley Coile
2015-11-25 19:19               ` Steffen Nurpmeso
2015-11-23 11:32 ` Charles Forsyth
2015-11-23 11:37   ` Charles Forsyth
2015-11-23 11:50 ` Brantley Coile [this message]
2015-11-23 12:05   ` Charles Forsyth
2015-11-23 12:17     ` Brantley Coile
2015-11-23 12:40       ` Charles Forsyth
2015-11-23 12:09   ` Charles Forsyth
2015-11-23 14:30 ` Charles Forsyth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6B7DA7E3-3917-4A67-9084-1B5DD90D97F9@me.com \
    --to=brantleycoile@me.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).