Note that there are some explanatory texts on larger screens.

plurals
  1. POc function-like macro with argument list but without replacement list?
    text
    copied!<p>A co-worker asked me to explain a bit of C code in <a href="http://memcached.org/" rel="nofollow">memcached</a>. I am at the point where I admit I do not understand it either.</p> <p>It has to do with C function-like macro definitions with parameters that do not also have a replacement list. For example, starting at line 2751 in memcached.c:</p> <pre><code> if (return_cas) { MEMCACHED_COMMAND_GET(c-&gt;sfd, ITEM_key(it), it-&gt;nkey, it-&gt;nbytes, ITEM_get_cas(it)); /* Goofy mid-flight realloc. */ if (i &gt;= c-&gt;suffixsize) { char **new_suffix_list = realloc(c-&gt;suffixlist, sizeof(char *) * c-&gt;suffixsize * 2); if (new_suffix_list) { c-&gt;suffixsize *= 2; c-&gt;suffixlist = new_suffix_list; </code></pre> <p>MEMCACHED_COMMAND_GET() is defined on line 23 in trace.h:</p> <pre><code>#define MEMCACHED_COMMAND_GET(arg0, arg1, arg2, arg3, arg4) </code></pre> <p>C macro function-like definition with arguments, ok. No replacement list.</p> <p>The output of cpp on memcached.c shows the function-like macro turns into ';':</p> <pre><code># 2751 "memcached.c" if (return_cas) { ; if (i &gt;= c-&gt;suffixsize) { char **new_suffix_list = realloc(c-&gt;suffixlist, sizeof(char *) * c-&gt;suffixsize * 2); if (new_suffix_list) { c-&gt;suffixsize *= 2; c-&gt;suffixlist = new_suffix_list; </code></pre> <p>Does anyone have any insight into why a programmer would include function-like macros without a replacement list like MEMCACHED_COMMAND_GET() that have no effect on the code produced? What purpose is being served by doing doing this? Thank you kindly in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload