title: Typecasting a pointer to change its size (in bytes)
body: <p>I'm trying to use pointers to move through a region of memory filled with hexadecimal values. I'm using a uint8_t pointer to ensure that it only points to 1 byte at a time. I want to go to a specific location (Offset number of bytes from the starting location) and store a group of bytes that is 1, 2, 4, or 8 bytes in length. I then want to interpret and print the value as either a signed or unsigned decimal (determined by an enum parameter).</p>
  
  <p>I thought that I could go simply change the pointer from a 1-byte uint8_t to the correct size for the number of bytes (eg. uint64_t for 8 btyes) and then store the value (because I can't just print it one byte at a time, I need to evaluate the whole byte/group of bytes). This is what I have so far:</p>
  
  <pre><code>void showValueAtOffset(FILE* Out, const uint8_t* const baseAddr, uint32_t Offset, Sign Sgn, uint8_t nBytes) {//------------------doesn't work----------------
     uint8_t *p = baseAddr;//create a pointer that points to the first byte of memory in the array
     for(int i = 0; i &lt; Offset; i++){//use a for loop to move p to the location indicated by Offset 
         p++;
     }
     if(nBytes == 1){
         //pointer p already has the correct typecast for the number of bytes
         uint8_t N = *p;//store the value of the byte
         if(Sgn == SIGNED){
             int8_t result = N;
             fprintf(Out, "%d  ", result);//print the value
         }
         else{//if UNSIGNED
             fprintf(Out, "%u  ", N);//print the value
         }
     }
     else if(nBytes == 2){
         uint16_t q = (uint16_t) p;//create the pointer q with the correct typecast for the number of bytes
         uint16_t N = *q;//store the value of the bytes
         if(Sgn == SIGNED){
             int16_t result = N;
             fprintf(Out, "%d  ", result);//print the value
         }
         else{//if UNSIGNED
             fprintf(Out, "%u  ", N);//print the value
         }
     }
     else if(nBytes == 4){
         uint32_t q = (uint32_t) p;//create the pointer q with the correct typecast for the number of bytes
         uint32_t N = *q;//store the value of the bytes
         if(Sgn == SIGNED){
             int32_t result = N;
             fprintf(Out, "%d  ", result);//print the value
         }
         else{//if UNSIGNED
             fprintf(Out, "%u  ", N);//print the value
         }
     }
     else if(nBytes == 8){
         uint64_t q = (uint64_t) p;//create the pointer q with the correct typecast for the number of bytes
         uint64_t N = *q;//store the value of the bytes
         if(Sgn == SIGNED){
             signed int result = (signed int) N;
             fprintf(Out, "%d  ", result);//print the value
         }
         else{//if UNSIGNED
              unsigned int result = (unsigned int) N;
              fprintf(Out, "%u  ", result);//print the value
         }
     }
     else{
         //this should not happen according to the preconditions
     }
     fprintf(Out, "\n");
  }
  </code></pre>
  
  <p>This does not work, and I get several errors like "invalid type arguement 'unary *' (have 'uint32_t')" and "warning: cast from pointer to integer of different size".</p>
  
  <p>What am I doing wrong?</p>