• 0 Posts
  • 1 Comment
Joined 1Y ago
cake
Cake day: Jul 01, 2023

help-circle
rss

Looks like this program is really old. It appears to be designed for a 32-bit system, the way it casts between unsigned int and pointers.

unsigned int is probably 32-bit even on your 64-bit system, so you’re only printing half the pointer with the printf, and only scanning half the pointer with the scanf. The correct data type to be using for this is uintptr_t , which is the same as uint32_t on a 32-bit system, and the same as uint64_t on a 64-bit system.

Try changing the type of addr to uintptr_t , and change lines 14-17 to this:

	printf("Address of main function: %p\n", (void *) &main);
	printf("Address of addr variable: %p\n", (void *) &addr);
	printf("\nEnter a (hex) address: ");
	scanf("%p", &addr);

You may have to include <stdint.h> . These changes should make the code portable to any 32-bit or 64-bit architecture.