undefined behavior: pay up or shut up
Academia recently discovered undefined behavior in C, twenty five years after industry tool vendors first started trying to help developers catch the problems it causes. Some of the tools that are now being written are doing stuff that we could only dream about back in the day.
The forces that morph occurrences of undefined behavior in source code to unwanted behavior during program execution have changed over the years.
- When developers paid for their compilers there was an incentive for compiler writers to try to be nice to developers by doing the right thing for undefined behaviors. Twenty five years ago there were lots of commercial compilers all having slightly different views about what the right thing might be; a lot of code was regularly ported to different compilers and got to encounter different compiler writer’s views.
- These days there is widespread use of open source compilers, which developers don’t pay for, removing the incentive for compilers writers to be nice to developers. Paying customers want support for new processors, enhancements to existing generated code quality and the sexy topic for PhDs is code optimization; what better climate for treating source containing undefined behavior as road kill. Now developers only need to upgrade to a later release of the compiler they are using to encounter an unexpected handling of undefined behavior.
A recent blog post, authored by some of the academics alluded to above, proposes adding a new option to gcc: -std=friendly-c
. If developers feel that this kind of option needs to be supported then they should contribute to a crowdfunding campaign (none exists at the time of writing) to raise, say, $500,000 towards supporting the creation and ongoing support for the functionality behind this option. Of course one developer’s friendly is another developer’s unfriendly, so we could end up with multiple funds each promoting an option that supports a view of the world that is specific to one target environment.
At the moment, in response to user complaints, Open source compiler vendors lamely point out that the C standard permits them to handle source containing undefined behaviors the way they do; they stop short of telling people to quit complaining and that they are getting the compiler for free.
If this undefined behavior issue starts to gain substantial publicity, but insufficient funding, open source compiler vendors will need to start putting a positive spin on the decisions they make. Not being in marketing I might have a problem keeping a straight face when giving the following positive messages:
- We are helping to save the world: optimized programs use less power (ok, every now and again they can use more). Do you really want to stop us adding more optimizations just because you cannot find the time to fix a mistake in your code?
- We are helping your application gain market share. Applications that are not actively maintained are less and less likely to continue to work with every release of the compiler.
Hello, Derek.
I am one of the co-authors of a blog post you cite in yours. However, I have not been working in academia ever since my post-doctoral year ended in 2003: the technological research branch of CEA I worked at afterwards works on applications in the same way that Fraunhofer institutes or SRI do. My work has been related to undefined behavior in C since then, “Academia recently discovered” narrative notwithstanding.
I currently work at a company the activity of which can, for the right public, be described as “helping its customers with undefined behavior”: http://trust-in-soft.com/
@Pascal Cuoq
Thanks for the background on your work. Perhaps academics and industrial researchers would have been a more accurate description.
I saw from your blog that you had jumped in at the deep end by joining a startup. Selling tools is a very tough business to be in. My experience with undefined behavior was that it did not cause enough problems for companies to be willing to buy a tool. There is a lot more interest in enforcing coding standards, which means you often have to bite your tongue (i.e., take the money and do what they want [since the customer is always right what they want you to do must be useful ;-]).
I wish you luck with your venture.