Hacker News new | ask | show | jobs
by Danieru 5056 days ago
I just spent the past 4 months programming a library in C89. I would have MUCH preferred C99 if only for inline variable declaration.

The key issue for my project was being cross platform. Since Microsoft's compiler does not implement C99 and never will, my hands were tied.

Now that's just my library. Other programers might be willing to decide case by case which features of C99 to use. Still if the document dates back to 2003 then C99 support everywhere would have been even more primitive. C89 would thus be the right decision for a introduction to C to avoid confusion.

1 comments

I'm curious: could you write your program in the subset of C99 that'll compile under C++, and then use C++ mode to compile it under Visual Studio?
I suppose I could but that'd be too complicated for my taste. In fact I wouldn't even need to go that far. Many of the most useful things are implemented as extensions to C89 in the popular compilers. Instead I stuck to pure C89 which I knew would be universally implemented. I like knowing that I can set GCC to ansi + pedantic and have a reasonable expectation of no drastic surprises.

C89 is primitive but charming in the simplicity. For instance while I disliked being forced to declare a function's variables before any code I now see that it encouraged me to keep functions very small. I would find ways to use fewer variables. Instead of 'for(int i = 0; i < max; i++)' I would use 'while(--max >= 0)', anything to avoid moving my cursor to the top of the function.

On the other hand I miss C++'s exceptions. Checking for errors all over the place gets ugly and bloats the codebase. What would otherwise be a two line copy operation between two objects gets two if blocks added which handle the miniscule chance of memory allocation failure in some other deeper frame.