Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is 0x000001, 0x000002, etc. ever a valid memory address in application level programming?

Tags:

c++

Or are those things are reserved for the operation system and things like that?

Thanks.

like image 763
johnny-john Avatar asked Dec 03 '25 08:12

johnny-john


2 Answers

While it's unlikely that 0x00000001, etc. will be valid pointers (especially if you use odd numbers on many processors) using a pointer to store an integer value will be highly system dependent.

Are you really that strapped for space?

Edit:

You could make it portable like this:

char *base = malloc(NUM_MAGIC_VALUES);
#define MAGIC_VALUE_1 (base + 0)
#define MAGIC_VALUE_2 (base + 1)
...
like image 200
Richard Pennington Avatar answered Dec 05 '25 23:12

Richard Pennington


Well the OS is going to give each program it's own virtual memory space, so when the application references memory spaces 0x0000001 or 0x0000002, it's actually referencing some other physical memory address. I would take a look at paging and virtual memory. So a program will never have access to memory the operating system is using. However I would stay away from manually assigning a memory address for a pointer rather than using malloc() because those memory addresses might be text or reserved space.

like image 26
Albinoswordfish Avatar answered Dec 05 '25 22:12

Albinoswordfish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!