Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Can I assume you want the empty definition and the <code>1</code> definition to be equivalent with the <code>0</code> is the different one? I'm pretty sure that question already exists on stackoverflow, but I can't find it.</p> <p>Here's a usenet thread on the same topic: <a href="https://groups.google.com/d/msg/comp.lang.c/jkI2vz8ZxmE/1-kOKCQ2MrwJ" rel="nofollow">https://groups.google.com/d/msg/comp.lang.c/jkI2vz8ZxmE/1-kOKCQ2MrwJ</a></p> <p>Several answers are given there. The cleverest one looks like:</p> <pre><code>#if -CONSTANTNAME+1 == 1 ... the "no CONSTANTNAME" branch #else ... the "yes CONSTANTNAME" branch #endif </code></pre> <p>If <code>CONSTANTNAME</code> is empty, <code>-+1 == 1</code> => false.</p> <p>If it's <code>1</code>, <code>-1+1 == 1</code> => false.</p> <p>If it's <code>0</code>, <code>-0+1 == 1</code> => true.</p> <p>If it's not defined, the default cpp replacement for unrecognized tokens applies, and that's a <code>0</code> so it's true.</p> <p><strong>UPDATE</strong></p> <p>If you want 3 branches, you can still use the <code>-FOO+0 == 1</code> test and add an extra test like <code>FOO+0==0</code>. Look at the results you can get:</p> <pre><code>Value of `FOO` `-FOO+1==1` `FOO+0==0` empty string false true 1 false false 0 true true </code></pre> <p>If the 4th case, macro not defined, is interesting, it must be tested with <code>#ifdef FOO</code> or <code>defined(FOO)</code> since it is otherwise indistinguishable from <code>0</code>.</p> <p>Sample code:</p> <pre><code>#if !defined(FOO) ... handle undef #elif -FOO+1 == 1 ... handle 0 #elif FOO+0 == 0 ... handle empty #else ... handle 1 #endif </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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