News for hackers. Stuff that matters.
Re:C for high level programmers (slides) by akkartik on Sunday May 31, 2015 @07:07PM (#9635957)
No mention of undefined behavior? That's the first thing I tell people about C, considering how easy it is to trigger.
Re:C for high level programmers (slides) by charlesL on Sunday May 31, 2015 @07:14PM (#9635974)
The issue with undefined behavior is it's kind of hard to... well... define. It's an odd combination of unsafe memory, float/integer rollover, and rules with memory allocation. I wasn't quite sure how to clearly state it.
Re:C for high level programmers (slides) by caf on Sunday May 31, 2015 @08:56PM (#9636272)
All you really need to say is: There are some rules in C which neither the compiler nor the runtime is required to check if you've broken. On the contrary, the implementation is allowed to assume that you haven't broken them - which means that if you do break these rules, all bets are off as far as the behaviour of your program goes, which may lead to all sorts of strange and apparently inconsistent results.
Re:C for high level programmers (slides) by akkartik on Sunday May 31, 2015 @07:22PM (#9636001)
Yeah I tend not to get hung up on the different ways it can trigger. It's more like, if you trigger it your program might run fine for now and then suddenly act up one day. It might die before the undefined behavior. It might launch nukes. Still sure you want to get into this? No? Want to go back to Ruby? Well, Ruby is built atop C. That's the five states of grief I try to get them through.
Re:C for high level programmers (slides) by kibibu on Sunday May 31, 2015 @10:40PM (#9636540)
Worse than that - undefined behaviour can cause optimization to make your software insecure.

http://blog.llvm.org/2011/05/what-every-c-programmer-should-...

Re:C for high level programmers (slides) by vortico on Sunday May 31, 2015 @07:14PM (#9635976)
There was a mention of garbage being returned from an out of bounds array.
Re:C for high level programmers (slides) by TheLoneWolfling on Sunday May 31, 2015 @08:05PM (#9636131)
Unfortunately, UB extends far beyond that. To the point of being (very) logically inconsistent.

People not familiar with C would naively expect that, for instance, `x[10] == x[10]` is always true even if 10 is out-of-bounds for x (or rather: it may crash, or it may be true.) . But compilers can - and will - assume that this situation is false if it makes the code faster.

This sort of thing is my major pain point with C - you quite literally have to know the entire code to make any judgements about any one piece of code, even trivial ones. You end up having to fight the compiler at every turn.

Re:C for high level programmers (slides) by missblit on Sunday May 31, 2015 @10:11PM (#9636462)
Not only can the compiler make it false. It can assume that the code would never make the comparison in the first place, and optimize away any cases where the undefined behavior is guaranteed to be triggered.

So in a sense undefined behavior can travel back in time :O

Re:C for high level programmers (slides) by TheLoneWolfling on Sunday May 31, 2015 @11:15PM (#9636636)
Yep.

It's impossible to have actual modular code in C. A real shock for people coming from higher level languages.

Re:C for high level programmers (slides) by xcogiz on Monday June 01, 2015 @05:45AM (#9637530)
What exactly do you mean by modular code in your context?

edit: Oh, you probably meant modules integrated directly in the language. I was surprised to read that since modular design is highly successful and useful in C.

Re:C for high level programmers (slides) by TheLoneWolfling on Monday June 01, 2015 @08:17AM (#9637982)
No, I'm not talking about modules. I'm talking about modular code:

I mean that in many languages it's at least possible to write code that can be understood fully in isolation. Objected-oriented programming, etc, etc.

In C that's impossible. Due to UB being global.