Liste des Groupes | Revenir à cl c |
On 23/04/2025 11:58, Muttley@DastardlyHQ.org wrote:On Wed, 23 Apr 2025 11:15:01 +0100>
bart <bc@freeuk.com> wibbled:IMV, macros generally are a bad idea. They are especially bad with how
they are implemented in C:
C macros do essentially 4 different things:
1) Provide a way to pass compilation data directly into the code via compilerswitches and #ifdef>
2) Allow conditional compilation for different OS's
That does not need expandable macros.
3) Allow repeating blocks of code to be compacted into a single macro when>
having a function instead would be more complicated and/or inefficient.
4) An alternative to inline functions. Probably the least useful.
* Their implementation is complex and poorly defined.
Maybe to you.
Have you ever implemented a C preprocessor?
>* Macros don't obey normal scope rules.
They're not supposed to.
So, is that good or bad? (Let me guess: it's good that it works like that!)
So what? You'd get a compilation error.>
If you're lucky. Or you get a silent, undetectable bug, since any
alphanumeric token: identifier, type, or reserved word, gets expanded,
no matter what the context.
Les messages affichés proviennent d'usenet.