title: static variables in switch statements
body: <p>I am working on a keil project using c. In one of my files, I have defined some variables at the top as static. I use them in some functions in this file and I also use them in a switch/case statement. For example:</p>
  
  <p>at the top where variables are defined:</p>
  
  <pre><code>static uint8_t* imageData = 0;
  static uint32_t height = 0;
  static uint32_t width = 0;
  static uint32_t stride = 0;
  </code></pre>
  
  <p>in the middle of the code:</p>
  
  <pre><code>switch (pMsg-&gt;MsgId)
  {
  
  case WM_CREATE:
  {     
      CAMERA_Init();   
      AMProcessor *processor = new AMProcessor();
  
      struct block blocks[2] = {
                                   {2, 240, 160},
                                   {2, 160, 120}                              
                              };
      processor-&gt;initBlocks(blocks, 2);           
      stride = 480; //sample_image.width;                                 
      processor-&gt;Initialize(480, 272, 480, InputTypes::CHROMA_MOBILE, InputTypes::RGB); 
      BSP_LED_Toggle(LED3);
  
      while(1){                               
          const PictureOutput* picOut = processor-&gt;ProcessImage((uint8_t *)CAMERA_FRAME_BUFFER);                              
          break;
      }
  }
  </code></pre>
  
  <p>and near the bottom I have a couple of functions that also use these variables.
  However, I am getting warnings that are telling me that the 4 variables defined at the top are initialized but never referenced.  If they are not static then I do not get this warning, but I get a hard fault error (which I am trying to get rid of). </p>
  
  <p>So my question is, why are these not referenced? It obviously has something to do with the static definition, but how come the static definition wouldn´t allow these to be referenced?</p>
  
  <p>for clarification: I am getting this message on all of them, even stride.
  warning:  #177-D: variable "imageData" was declared but never referenced</p>
  
  <p>I have a function at the bottom that uses all of these variables that looks like this:</p>
  
  <pre><code>bool ReadImageFromPgmFile(const char* pFileName, uint32_t &amp;height, uint32_t &amp;width, uint8_t*&amp; ImgData) {
      if (pFileName == 0) {
              return false;
      };
  
      // read data from file
      if (strstr(pFileName, ".pgm") || strstr(pFileName, ".PGM")) {
              FILE *pPgmFile = fopen(pFileName, "r");
  
              if (pPgmFile == NULL) {
                      fprintf(stderr, "Cannot open PGM file '%s'.\n", pFileName);
                      return false;
              };
  
              char x = fgetc(pPgmFile);
              char y = fgetc(pPgmFile);
  
              if (x != 'P' || y != '5') {
                      fprintf(stderr, "Invalid PGM file '%s'.\n", pFileName);
                      return false;
              };
  
              uint32_t maxvalue;
              fscanf(pPgmFile, "%d", &amp;width);
              fscanf(pPgmFile, "%d", &amp;height);
              fscanf(pPgmFile, "%d", &amp;maxvalue);
  
              if (maxvalue &gt; 255) {
                      fprintf(stderr, "File '%s' has incorrect format.\nOnly 8-bit PGMs are supported by this reader.\n", pFileName);
                      return false;
              };
  
              ImgData = new uint8_t[width*height];
              memset(ImgData, 0, width*height);
              fgetc(pPgmFile);                // skip new line character
              uint32_t nPixelsRead = fread(ImgData, 1, width * height, pPgmFile);
              fclose(pPgmFile);
  
              if (nPixelsRead != width * height) {
                      fprintf(stderr, "PGM file '%s' does not contain all pixels.\n", pFileName);
                      return false;
              };
  
              return true;
      }
  
      return false;
  };
  </code></pre>