title: C: Cannot declare pointer inside if statement
body: <p>I have a pointer which points to a function. I would like to:</p>
  
  <pre><code>  if (mode == 0)
    {
    const unsigned char *packet = read_serial_packet(src, &amp;len);
  
    } else {
    const unsigned char *packet = read_network_packet(fd, &amp;len);
    }
  </code></pre>
  
  <p>But I cannot do it because my compiler complains when I first use the pointer later in the code.</p>
  
  <pre><code>   error: 'packet' undeclared (first use in this function)
  </code></pre>
  
  <p>This is strange. It worked without the if statement, but now I need my program to be able to get data from different sources. Isn't it possible to do this? I think so. If it isn't, is there any other simple way to get what I am trying?</p>
  
  <p>Thanks a lot.</p>