tags:

views:

347

answers:

3

Nearly every (relatively) new book about c programming I've seen doesn't seem to adhere to the C99 standard, or they cover it in an extra chapter. Comming from a Java background, the C99 standard made the migration (well, still migrating ^^) much easier for me, and this probably applies to other languages, too.

It seems like C99 hasn't reached most of the C developers yet. But why?

+10  A: 

Short answer: compiler support is slow to get installed and c programmers are a conservative lot who change their behavior slowly.

dmckee
For a short answer I'd say it is pretty good.
ChaosPandion
+3  A: 

The risk of switching to a new compiler on an existing code base is generally unknown, but it can be quite painful, its wisest to only switch when you have months of time to shake out any bugs/changes. And for really old code bases, sometimes It's wisest to just never switch at all.

I'd be willing to bet that the majority of projects that use C aren't willing to switch to C99 at all since there's hardly any upside for a large existing code base and quite a bit of potential downside. I worked at one large software house that checked the compilers into th source tree right along side the code and would never switch compilers for a product.

John Knoeller
But which compilers do they use to compile those checked-in compilers? :-)
R..
@R: the compilers were binary checkins, not source checkins.
John Knoeller
+5  A: 

I strongly suspect it's mainly because MSVC does not attempt to support C99, and quite likely never will. There are a few embedded compilers in the same boat, but they're hardly common enough to matter much individually. AFAIK everyone else is at least trying to implement C99 as much as possible.

There isn't much reason in practice not to use selected features of C99, but if you're going to learn and write to one C standard, and only one, then it must be C89.

Furthermore, it's probably quite difficult and confusing to write an introductory C text which starts out by saying "OK, there are two different standards, and I'm going to use three different colours of text: one for C89, one for C99, and one for both". It's also probably harder to write about C99 for a whole book, and then "take back" a lot of what you've said in an appendix about C89, than it is to write about C89 and then add to it in an appendix about C99.

All speculation, though. Really you'd have to ask the authors of the books you're reading (or perhaps in some cases go against all your programming instincts, and read the foreword ;-))

Steve Jessop
I don't buy the argument that if you're only going to learn and write to one standard, it must be C89. gcc supports generating code for nearly every platform of any possible relevance, so why not just use the modern standard, C99?
R..
@R. If you have a better explanation, go ahead. I'm not saying that all those people are *sensible* to use Microsoft's compiler for C, I'm just saying that there's enough of them to have an influence. When I've set out to write "portable C code", I haven't had the option to tell certain customers to switch compilers, or compile my bits separately from the rest of their project. So I've used C89. It's a little bit like having to write web pages that work in IE6 - there's only so much benefit in telling a proportion of your audience that they're idiots. At least C89 isn't actually awful.
Steve Jessop