Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Muttley@DastardlyHQ.org Newsgroups: comp.lang.c Subject: Re: Loops (was Re: do { quit; } else { }) Date: Wed, 23 Apr 2025 10:58:12 -0000 (UTC) Organization: A noiseless patient Spider Lines: 44 Message-ID: References: <87ecxmv4t4.fsf@nosuchdomain.example.com> <20250420200823.908@kylheku.com> <20250421113640.839@kylheku.com> <20250421125957.29@kylheku.com> <20250422103555.547@kylheku.com> <20250422142113.403@kylheku.com> <20250422164415.883@kylheku.com> Injection-Date: Wed, 23 Apr 2025 12:58:12 +0200 (CEST) Injection-Info: dont-email.me; posting-host="7ca9f6b3c496151fa10fed8be15037ad"; logging-data="3109361"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jnqw8Z/0+lElppeDqn3Va" Cancel-Lock: sha1:sqXcaSYxIIT2TFD3BeuDZJgARyg= Bytes: 2798 On Wed, 23 Apr 2025 11:15:01 +0100 bart 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.