Author Topic: friendly C  (Read 7777 times)

kyle

  • Newbie
  • *
  • Posts: 48
    • View Profile
friendly C
« on: September 03, 2014, 12:46:40 AM »
John Regehr has a new blog post about "friendly C".  This is not any sort of syntax change, and thus may not be all that useful here, but instead is a set of changes he wants to make to how compilers handle C code to make the results less surprising.

http://blog.regehr.org/archives/1180

I haven't been caught by undefined behavior in C compilers too often, but some of the cases I've read about can be very, very difficult to debug.

Best,
Kyle

bas

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: friendly C
« Reply #1 on: September 03, 2014, 09:08:33 AM »
Hi Kyle,

yet another nice article!
What are you looking for yourself when you find these articles?
Do you have a particular interest?

Cheers,
Bas

kyle

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: friendly C
« Reply #2 on: September 05, 2014, 03:43:19 AM »
I read John Regehr's blog from time to time.  He write very clearly and covers interesting topics.  His articles on undefined behavior were so horrifying (as were Chris Lattner's) that I wanted to start writing in assembly because I did not trust what any compiler did.  I actually started looking at Java again too because it does specify some of the corner cases that have become problems in C.

C11 could be worse than usual because of the consume memory order sematics that are required (but nothing stronger!).  I am still reading up on that.

I am interested in compilers in general and C in particular :-)

Here are a few more to understand some of the threading issues I've run into myself when the semantics of barriers and locks are not clear:

http://preshing.com/

Preshing is another one who writes very informative articles.  The latest article is about C++11's consume memory ordering.  You can read about that to see why C's adoption of the same thing is going to be problematic.  Linus Torvolds wrote (i.e. flamed) about it somewhere...  Hmm, can't find the post.  Perhaps it was on Real World Technologies?  No search there...

The articles over time from Regehr and Lattner show that C is slowly becoming a language that is difficult to understand.  Even the concept of NULL can be abused by optimizers to the point where you cannot easily figure out what is happening with simple code.  Read some of Lattner's examples.  They are a bit scary.  I see code like them all the time :-(

So, I would love to see a language that can supplant C in utility, but the semantics turn out to be really tricky!  C went from a high level assembler to a language that you cannot fully trust without knowing a huge amount about your specific compiler.   Not what I want.

I have three jobs and a small child (mortgages are expensive!), so I don't think I am going to write the next C replacement.  All I can do right now is cheer from the audience :-/

Best,
Kyle