Home > database >  Why do C variables have peculiar 40-bit memory addresses on Android 12?
Why do C variables have peculiar 40-bit memory addresses on Android 12?

Time:06-06

I have this simple code which prints the address of a variable to stdout:

#include <stdio.h>
int main()
{
    int a=0;
    printf ("Address of a: %p", (void*)&a);
    return 0;
}

Executing this code on an Android 11 (32-bit OS) device gives the output as:

Address of a: 0xffd7458c

which is a 32-bit memory address, as expected.

But executing this code on an Android 12 (64-bit OS, as far as I know) device gives the output as:

Address of a: 0x7fdfee014c

which is an unusual 40-bit memory address.

So my question is, shouldn't the memory addresses on Android 12 be 64-bit (i.e. something like 0x7fdfee014c346a5f) as it is a 64-bit operating system?

A detailed explanation would be much appreciated.

CodePudding user response:

Unless your 64-bit Android phone has 18 EXA-bytes of memory (that's 18 BILLION gigabytes), the memory map will be sparse. It would appear that your memory (RAM?) is mapped into the address space handled by 40-bits of address.

  • Related