3 ms·
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 t
by WalterBright 2y ago
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:
#define BEGIN {
#define END }
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.
- lor_louis 2y agoTo be fair, I'd rather type BEGIN instead of <<? Or whatever the trigraph is supposed to be. We tend to forget that a lot of computers didn't have the keys to type "mathematical" symbols.
- WalterBright 2y agoEBCDIC was already dead in the 1980s. Nobody ever used the trigraphs except for one company that hung on for years until even the C++ community decided enough was enough and dumped them. Besides, what people wrote was: #define BEGIN { not: #define BEGIN <<?
- kazinator 2y agoStephen Bourne used such macros in the Bourne Shell sources to make the code resemble Algol. The source is very clear and readable.
- WalterBright 2y agoHave you adopted his macros in your own projects?
- kazinator 2y agoNo because even if I could identify a benefit to these macros (which I can't in the contexts in which I work) there's a cost to using them. Macros whuch simply transliterate tokens to other tokens without performing a code transformation do not have a compelling technical benefit. Only a non-technical benefit to a peculiar minority of users. In terms of cost, the readability and writeability are fine. What's not fine is that the macros will confuse tooling which processes C code without necessarily expanding it through the preprocessor. Tooling like text editing modes,identifier cross-referencers and whatnot. I've used C macros to extend a language with constructs like exception handling. These have a syntax that harmonizes with the language, making then compatible with all the tooling I use. There's a benefit because the macro expansions are too verbose and detailed to correctly repeat by hand, not to mention to correctly update if the implementation is adjusted.