6

It looks like K&R "C Programming Language (2nd Edition)" covers ANSI C, but another book that I'm starting (Stephen G. Kochan "Programming in C") says that it uses C99.

I'm coming from a C#/JavaScript/Python/PHP/Java background and looking to round out my skills.

I'm currently using GCC, but I'm curious about Clang. Which version is used more in new and existing code? Does it even matter, or should I learn both?

Matthieu
  • 4,559
  • 2
  • 35
  • 37
Nogwater
  • 171
  • 1
  • 5

4 Answers4

15

Learn C89 first, then learn everything that is different between C89 and C99.

A good book covering both is C Programming: A Modern Approach.

I think C89 gets used the more; GNU uses it and then, most compilers don't even support C99 (fully). GCC supports C99 only partially. Myself, the only C99 features I use are variable length arrays and single-line comments. If you want maximum portability, choose C89 for your projects, but it is still important to at least be aware of C99's features.

Anto
  • 11,157
  • 13
  • 67
  • 103
3

I think you are confusing C language standards and specific extensions offered by compilers.

As for standards, I would learn the latest you can use to produce running code.

As for compiler, I would try to stay away from extensions as long as possible. Consider compiling in a highly standard-compliant mode (e.g. -pedantic for gcc and clang). This makes your code more portable and helps you understand the language better.

Benjamin Bannier
  • 1,212
  • 8
  • 15
1

In one respect, it doesn't matter. As you build a career in programming, you're certain to encounter C, C89, C99, C++ in some variant forms, C#, Java (as a quasi-variant of C) and Objective-C (as another quasi-variant) The goal, in my opinion, would be to establish yourself as a competent programmer first, and then any language you see, including Fortran, Cobol, or Basic, will be easy to read and understand, and therefore easy to adapt to.

In that sense, an early focus on any one of those languages is fine, as long as you're prepared to adapt to the other languages as they come along.

So I say this: If you're making this a focus of academic study, then choose the most popular standard C variant in use today, and do your learning while adhering strictly to the standard set. Following that, make an analysis of the differences between your choice, and the differences.

If this is a professional focus, you're going to want to learn C# and Objective-C and know them both cold, eventually, unless you're maintaining code. And if you're a smart professional, you're also becoming expert in PHP, Python, Ruby, Visual Basic (y'know, just. in. case.) etc, etc, etc...

Rob Perkins
  • 521
  • 4
  • 17
  • Or better yet, the OP should learn Java and C++. Anyone wishing to work in enterprise software development needs to know Java. C++ is still the primary language used in game development. – bit-twiddler Apr 10 '11 at 04:09
  • C++ as late as possible, unless you're getting into scenegraphs. And even then, kinda meh; C++ is a lexical and syntactic travesty. – Rob Perkins Apr 13 '11 at 03:20
  • All languages involve trade offs. The Java ecosystem is a nightmare, and C# pretty much locks one into the Microsoft world. The thing that I hate most about Java and C# is that both of these languages lack copy constructors, which makes creating deep copies of collections that contain derived classes a nightmare. There is no 100% safe way to create a deep copy of a collection that contains classes that are not derived from serializable classes in either language. – bit-twiddler Apr 13 '11 at 14:09
  • Just have to preempt the need with a design pattern. (C# and Java are also lexical travesties; what is "}}}}" supposed to mean, anyway, all by itself, for example? It's too implicit in places like that, and readability suffers.) – Rob Perkins Apr 13 '11 at 17:03
  • It is funny that you mentioned solving the problem with a design pattern. I never had to make a deep copy of a Java collection until I worked on a very large Swing-based application that suffered from design patternitis. It has been my experience that heavy use of design patterns tends to bloat the code base, which, in turn, drives up the cost of maintenance. Used judiciously, design patterns can simplify a design; however, far too many developers are making problems fit a design pattern (or a set of design patterns) instead of designing a solution that fits the problem. – bit-twiddler Apr 13 '11 at 18:46
0

Use the C-subset of C++. Being able to define variables close to where they are initialized and used is better than having C force you to declare a list of variables at the top.

Lord Tydus
  • 1,429
  • 1
  • 10
  • 12