
What Every C Programmer Should Know About Undefined Behavior #3/3 - ryannielsen
http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.html
======
pohl
That this series has been published so close to WWDC makes me wonder if we're
being prepared for some announcement.

 _Edit: although it's more likely that Lattner is just bracing himself for the
onslaught of questions he'll have to field and hoping to be able to refer
people to these articles._

------
joe_the_user
OK,

I've vaguely looked at each of these, being a c++ programmer rather a "true" c
programmer.

One thing that was a little annoying was their discussion about purpose of
undefined behavior. That is, I don't believe "undefined behavior" in the C
Language exists for speed _as such_. Rather, undefined behavior is machine-
specific behavior and it exists in C so the programmer can write machine
specific code, the C Language being a "high-level assembly language" or
"system-programmer's Swiss army knife". Speed is one outcome, certainly but
there are other ways to get speed (a Just In Time Compile can come at least
close naive c code). The _point_ isn't speed. The _point_ is "do anything",
the point is that a chip designer can write c code and look on his screen to
see the resulting assembler and decide where to go from there.

It may be the llvm folks bypass this point because llvm is "virtual machine"
rather than a chip. But it is slight annoying not to mention this if "What
Every C Programmer Should Know"

Perhaps they should have called their article "what C-programmers should know
about optimizing compilers..."

~~~
pohl
_One thing that was a little annoying was their discussion about purpose of
undefined behavior._

Could you quote an offending passage that claims that the purpose of undefined
behavior is for speed? I see discussion of how undefined behavior creates
opportunities for optimization, but nothing about purpose. Indeed, the word
"purpose" does not appear in parts 1, 2, or 3 at all.

So please share whatever passage has the semantics you claim.

 _It may be the llvm folks bypass this point because llvm is "virtual machine"
rather than a chip._

I'm curious: what exactly do you mean by this?

I don't mean to be rude, but whenever I read anybody say that LLVM is a
virtual machine, it always comes off as if everything they know about LLVM
came from learning the acronym.

~~~
joe_the_user
Pohl: Could you quote an offending passage that claims that the purpose of
undefined behavior is for speed?

Me: How a-bout, "Undefined behavior exists in C-based languages _because_ the
designers of C wanted it to be an _extremely efficient_ low-level programming
language."*??

Seems pretty clear. You don't necessarily need the literal term "purpose" here
- the term "because" in this passage implies purpose
([http://blog.llvm.org/2011/05/what-every-c-programmer-
should-...](http://blog.llvm.org/2011/05/what-every-c-programmer-should-
know.html) \- yes, that's first article, sorry).

~~~
pohl
I see, it's a historical claim without a citation. What kind of machine was it
back then, a PDP-11? I suppose it's possible they would want to save cycles
here & there. Do you know something specific about the history here?

