Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use ANSI C (C89)?

Tags:

It's 2012. I'm writing some code in C. Should I be still be using C89? Are there still compilers that do not support C99?

I don't mind using /* */ instead of //.

I'm not sure about C89 forbids mixing declarations and code. I'm kind of leaning towards the idea that it's actually more readable to have all the declarations in one place, and if it isn't, the function is too long.

VLAs look useful but I haven't needed them yet.

Should I stick with C89 if I don't have a compelling reason not to? Are there other things I haven't considered?

like image 407
mk12 Avatar asked Aug 12 '12 21:08

mk12


People also ask

Should I use C89?

In conclusion, if you want portability for embedded or restricted systems, dynamic compilation, MSVC, or compatibility with proprietary source code, I would say C89 is advantageous.

Is ANSI C still used?

Although this document was subsequently adopted by ISO/IEC and subsequent revisions published by ISO/IEC have been adopted by ANSI, "ANSI C" is still used to refer to the standard.

What is the most used C standard?

Since the most popular C standard followed by the academia in India is still ANSI C, I will mention a few differences between K&R C and ANSI C. “There are 32 keywords in C,” is one of the clichés I utter in many of my C programming classes.


2 Answers

Unless you know that you cannot use a C99-compatible compiler (the Visual Studio C compiler is the most prominent candidate) there is no good reason for not using the nice things C99 gives you.

However, even if you need to support that compiler you can use some C99 features - just not all of them.

One feature of C99 that is incredibly handy is being able to do for(int i = ...) instead of having to declare your loop variable on top of the function - especially since C actually has a block scope. That's the kind of declaration where having it on top really doesn't improve the readability.

like image 77
ThiefMaster Avatar answered Sep 23 '22 06:09

ThiefMaster


There is a reason (or many) why C89 was superseded by C99. If you know for sure that no C99 compiler is available for your particular piece of work (unlikely unless you are stuck with Visual Studio which never supported C officially anyway), then you need to stay with C89 but otherwise you should certainly put yourself in a position where you can benefit from the last 20+ years of improvement. There is nothing inherently slower about C99.

Perhaps you should even consider looking at the newest C11 standard. There has been some important fixes for dealing with Unicode that any C programmer could benefit from (other changes in the standard are absolutely minimal)...

like image 31
Mathias Schwarz Avatar answered Sep 22 '22 06:09

Mathias Schwarz