title: Pointer Arithmetic for mmap
body: <p>recently I was attempting to adapt someone's mmap code and came across the following error. (I am actually a bit dubious about their code now as it looks like they are doing something unnecessary - attempting to use MAP_FIXED with their own page aligned memory. The manpage suggests calling mmap with NULL as the addr argument should do this on Linux. )
  So I think I will at least test calling mmap with a NULL address. However I don't quite understand the error gcc is throwing up at me when I changed it. Their code works ok while I get <strong>lvalue required as left operand of assignment</strong>.</p>
  
  <p>Essentially they were doing the following:</p>
  
  <pre><code>    uint8_t * ptr = (uint8_t *)mem;
      if ((uint32_t)ptr % PAGE_SIZE)
      {
          ptr += PAGE_SIZE - ((uint32_t)ptr % PAGE_SIZE);
      }
  </code></pre>
  
  <p>Where mem is a void * to some malloc'd memory.</p>
  
  <p>I am trying more or less the same with typecasts:</p>
  
  <pre><code>    if ((uint32_t)mem % PAGE_SIZE)
      {   
          (uint8_t *)mem += PAGE_SIZE - ((uint32_t)mem % PAGE_SIZE); /* ERROR */
      }
  </code></pre>
  
  <p>So I thought I was being smart and removing a variable which wasn't in my mind required.
  Could someone enlighten me on why my typecasting is off?
  Cheers.</p>