title: Are there any restrictions to the C standard allowing functions to be implemented as macros?
body: <p>Often, in addition to providing a function declaration, C standard headers may provide a "masking macro" to make things speedier.  For example, if I include <code>ctype.h</code>, the header file will declare</p>
  
  <pre><code>int isdigit(int c);
  </code></pre>
  
  <p>But it may also mask the declaration with a macro.  I believe this is a portable <code>isdigit</code> macro according to the C standard:</p>
  
  <pre><code>#define isdigit(c) ((c) &gt;= '0' &amp;&amp; (c) &lt;= '9')
  </code></pre>
  
  <p>Of course, this macro is also dangerous because it introduces undefined behavior if you do this while the macro is defined:</p>
  
  <pre><code>int c = 'A';
  printf("%d\n", isdigit(c++));
  </code></pre>
  
  <p>To avoid UB in this hypothetical case, I have to surround the function name with parens:  <code>(isdigit)(c++)</code>.  So, my question is:  are there any restrictions to what sort of masking macros a standard header can define?  Are they guaranteed to not cause undefined behavior if an argument expression has side effects, or are they technically allowed to have weird behavior such as we see above?  Where are the limits?</p>