Sujet : Re: Loops (was Re: do { quit; } else { })
De : Muttley (at) *nospam* DastardlyHQ.org
Groupes : comp.lang.cDate : 23. Apr 2025, 11:58:12
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vuah44$2usfh$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
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 compiler
switches and #ifdef
2) Allow conditional compilation for different OS's
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.
* Compiler error messages can get weird and confusing
If you think C errors are confusing try C++ with template errors.
* They cause problems for tools such as smart editors
Any "smart" editor that can't cope with macros isn't smart.
* Macros don't obey normal scope rules.
They're not supposed to.
* Macro solutions tend to be ugly and tacky (see X-macros)
So can any code.
* Macro expansion can do too much:
>
#define length 200
#define width 100
>
struct {char* str; int length;} s;
s.length = 0; // oops!
So what? You'd get a compilation error.