▲ | kazinator 2 days ago | ||||||||||||||||||||||||||||||||||||||||
Heavy use of macros could be why C went mainstream. Macros gave C efficient inline functions without anything having to be done in the compiler. Doing things like "#define velocity(p) (p)->velocity" would instantly give a rudimentary C compiler with no inline functions a performance advantage over a crappy Pascal or Modula compiler with no inline functions, while keeping the code abstract. And of course #if and #ifdef greatly help with situations where C does not live up to its poorly deserved portability reputation. In languages without #ifdef, you would have to clone an entire source file and write it differently for another platform, which would cause a proliferation due to minor differences (e.g. among Unixes). Ah, speaking of which; C's #ifdef allowed everyone to have their own incompatible flavor of Unix with its own different API's and header files, yet get the same programs working. An operating system based on a language without preprocessing would have hopelessly fragmented if treated the same way, or else stagnated due to discouraging local development. Thanks in part to macros, Lisp people were similarly able to use each other code (or at least ideas) in spite of working on different dialects at different sites. | |||||||||||||||||||||||||||||||||||||||||
▲ | WalterBright 2 days ago | parent [-] | ||||||||||||||||||||||||||||||||||||||||
You're quite right in that early C was a primitive compiler, and adding a macro processor was a cheap and easy way to add power. Using the macro preprocessor to work around some fundamental issues with the language is not what I meant. I meant devising one's own language using macros. The canonical example:
We laugh about that today, but the 80's people actually did that. Today's macros are often just more complicated attempts at the same thing.The tales I hear about Lisp is that a team's code is not portable to another team, because they each invent their own macro language in order to be able to use Lisp at all. | |||||||||||||||||||||||||||||||||||||||||
|