https://software.codidact.com/categories/38/tags/4407.rssNew Posts Tagged 'macros' - Software DevelopmentSoftware Development - Codidact2023-11-21T14:31:42Zhttps://software.codidact.com/posts/279576What is do { } while(0) in macros and should we use it?Lundinhttps://software.codidact.com/users/81762020-11-26T07:57:05Z2023-11-21T14:31:42Z<p><strong>Background</strong></p>
<p>I can see the need to use <code>{ }</code> when implementing a function-like macro such as this one:</p>
<pre><code>#define HCF(code) fprintf(stderr, "halt a...https://software.codidact.com/posts/290205When should I parenthesize macro arguments in C?alxhttps://software.codidact.com/users/539372023-11-10T23:47:04Z2023-11-13T14:39:59Z<p>I've seen macros use parentheses to enclose its arguments. Most of these make sense, as in</p>
<pre><code class="language-c">#define sum(a, b) ((a) + (b))
</code></pre>
<p>The outer prevent...https://software.codidact.com/posts/286575How to write a macro that discards the const qualifier, for any type?alxhttps://software.codidact.com/users/539372022-06-10T14:55:22Z2022-11-02T23:03:17Z<p>How to write a macro that discards the const qualifier, for any type?</p>
<p>I hope some combination of <code>typeof</code> and a cast will do, but haven't found the combination.</p>
<p>I trie...