4 ms·
C would be a lot harder to write without the preprocessor. I have only really had one truly awful experience with the preprocessor in the last 15 years and it w
by Asooka 4y ago
C would be a lot harder to write without the preprocessor. I have only really had one truly awful experience with the preprocessor in the last 15 years and it was when reading OpenSSL's code. Even then, I didn't have too much trouble to grok it with just Vim.
- WalterBright 4y agoI discovered my C code was a lot better when I backed out all the clever metaprogramming preprocesser usage. C could be easily extended with: 1. modules 2. manifest constants 3. conditional compilation and the preprocessor can be deprecated.
- jessermeyer 4y agoThis kind of insight was a driving force in the design of https://odin-lang.org/ https://odin-lang.org/
- zajio1am 4y agoFor me, it is hard to imagine to program in C without preprocessor metaprogramming. Obviously, it would be better if generic types and metaprogramming were available directly in the language. Alternative is either copying code and adapting it manually, or depending on generic code with many void * arguments.
- WalterBright 4y agoIf one really needs metaprogramming, it's time to move to a more powerful language. There are plenty of them.
- arinlen 4y ago> If one really needs metaprogramming, it's time to move to a more powerful language. It's wholly wrong to try to frame this as "more powerful", specially considering the fact that C already supports generic selection. https://en.cppreference.com/w/c/language/generic https://en.cppreference.com/w/c/language/generic > There are plenty of them. There really isn't, at least in the application domains where C dominates, such as embedder programming. You'd be hard pressed to find any producrion-level tool chain for embedded development which supports anything other than C or even C++, and any decision to pick up even C++ over C for embedded development requires a lot of soul searching.
- kaba0 4y agoNah, the C preprocessor is a disgusting hack. I really don’t understand why they didn’t opt for a more logical, AST-based macro system when the base language has such bad expressivity in itself.