Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8188437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:54:46+00:00 2026-06-07T02:54:46+00:00

recently I was attempting to adapt someone’s mmap code and came across the following

  • 0

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 lvalue required as left operand of assignment.

Essentially they were doing 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 a void * to 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); /* ERROR */
    }

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:54:48+00:00Added an answer on June 7, 2026 at 2:54 am

    The mistake you’re making is:

    (uint8_t *)mem += /* Anything.  */
    

    You simply cannot assign to the result of a cast. The result of a cast is not the same value as the original expression.

    Think about how weird it would be to do:

    (int) some_char_variable = 9999;
    

    I had trouble for the same reason once.

    Use a temp, and write back the result, OR, as R.. says in their comment:

    mem = (void *) ( ( (uint8_t *) mem) + SOME_EXPRESSION );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I put together a test table for a error I recently came across. It
Recently I've spotted a very disturbing issue. I've got the following python code: for
Recently I was trying some practice programs in python and I came across this
I recently learned about CTE's in SQL Server and am attempting to use it
Recently, I came across this one stone kills multiple birds framework - http://phonegap.com/ .
Bah! I have recently installed the MiniProfiler from http://code.google.com/p/mvc-mini-profiler/ attempting to find all the
I recently discovered that attempting to resolve 127localhost.com on (at least OSX Lion) resolves
Recently I have been learning about WMI and WQL. I found out the list
Attempting to do SetData() on Texture2D that has been recently Draw()-n by SpriteBatch leads
I recently downloaded the latest stable release of Gnu Octave, and was attempting to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.