Home > Articles > Programming > C/C++

What Is C For?

  • Print
  • + Share This
From the author of

A Real Preprocessor

Okay, I admit that this feature is a bit of a stretch. The C preprocessor is simultaneously the best and worst feature of the language. Best, because it makes certain kinds of metaprogramming much easier than they would be in languages like Java, which lack the preprocessor. Worst, because the preprocessor is so much more limited than something like the LISP preprocessor.

The big problem with the C preprocessor is that it only allows substitutions on tokens. In an ideal world, something like Objective-C would be implementable entirely in the C preprocessor. Class definitions in Objective-C are just C structures with an initializer routine, methods are just C functions with two hidden variables, and classes are just C structures. Apart from the type checking, translating Objective-C into C is a fairly simple operation.

This would be possible if the preprocessor had state—if #defines could #define other things, and include nested conditionals. This would make implementation of the preprocessor significantly more difficult, however, and so is unlikely to be popular with compiler writers.

  • + Share This
  • 🔖 Save To Your Account