I recently tried to adapt the mmap code and came across the following error. (Actually, I doubt their code a bit, because it looks like they are doing something unnecessary - an attempt to use MAP_FIXED with their own page-aligned memory. The manpage suggests calling mmap with NULL, since the addr argument should do this on Linux. ) Therefore, I think that at least I will test the mmap call with a NULL address. However, I do not quite understand that the gcc error pounced on me when I changed it. Their code works fine as long as I get the
lvalue as the left assignment operand .
Essentially they did the following:
uint8_t * ptr = (uint8_t *)mem; if ((uint32_t)ptr % PAGE_SIZE) { ptr += PAGE_SIZE - ((uint32_t)ptr % PAGE_SIZE); }
Where mem is the void * in some malloc'd memory.
I am trying more or less the same with typecasts:
if ((uint32_t)mem % PAGE_SIZE) { (uint8_t *)mem += PAGE_SIZE - ((uint32_t)mem % PAGE_SIZE); }
So, I thought I was smart and delete the variable that I don't need. Can someone enlighten me about why my actuation does not work? Greetings.
source share