title: Overload function in C language using _Generic mix function call with constants returning
body: <p>I see there are two ways of writing a <code>_Generic</code> statement:</p>
  <p>A.</p>
  <pre><code>#define len(x) _Generic((x), char*:f1, int: f2, char: f3, double:f4) (x)
  </code></pre>
  <p>I want to underline the <strong>(x)</strong>.</p>
  <p>B.</p>
  <pre><code>#define len(x) _Generic((x), char*:f1(x), int: f2(x), char: f3(x), double:f4) 
  </code></pre>
  <p>The problem is that in the B case, I got errors:</p>
  <ol>
  <li>expected char* but argument is of type int</li>
  <li>incompatible type for argument 1 of f...</li>
  </ol>
  <p>How Am I suppose to write this overload if I want to mix functions with constants?</p>
  <p>I'm trying to get:</p>
  <ul>
  <li><p>1 if the argument is of type char;</p>
  </li>
  <li><p>the length of the string if the argument is of type char *;</p>
  </li>
  <li><p>the number of decimal digits (possibly increased by one when the argument is negative) if the argument is of type int;</p>
  </li>
  <li><p>the length of the string produced by the printf() function using the %f specifier if the argument is of type double.</p>
  <pre><code> int_len(int number)
   {
       unsigned counter=0;
       if(number &lt; 0)
       {
           counter++;
       }
  
       while(number)
       {
           counter++;
           number /= 10;
       }
       return counter;
   }
   int char_len(int param)
   {
       return 1;
   }
  
   int double_len(double param)
   {
       return 10;
   }
  
   int charptr_len(char* ptr)
   {
       unsigned count=0;
       while(*ptr)
       {
           ptr++;
           count++;
       }
       return count;
   }
  
  
   #define len(x) _Generic((x), char*:charptr_len(x), int: int_len(x), char:1, double:double_len(x))
  
   int main(void) {
       printf(&quot;%d\n&quot;,len(261321));
       printf(&quot;%d\n&quot;,len(261.321));
       printf(&quot;%d\n&quot;,len((char)'x'));
       printf(&quot;%d\n&quot;,len(&quot;A kingdom for a horse!&quot;));
       return 0;
   }
  </code></pre>
  </li>
  </ul>
  <p>p.s I know the code might be stupid but I just wanted it to work .</p>