C: Addresses

Mi'kail Eli'yah
6 min readApr 29, 2024

Similar to memory manipulations and allocation, address management, are hidden in their own ways in various OS.

Test usages for different test cases:

test_usages_00.c

test_usage_reading_addresses()
test_usage_memory_bound()
test_usage_memory_reassignment()
test_usage_locating_stack_address()
test_usage_check_distance_between_addressed_memory()

test_usages_01.c

test_usage_check_memory_address_assignment()

There are times we want to know where (i.e. memory region) it is executing from.

#include <stdio.h>
#include <stdint.h>


// Function to be pointed to
int add(int a, int b) {
return a + b;
}


int main() {
// Define a function pointer with the same signature as the function to be pointed to
int (*funcPtr)(int, int) = &add;


// Print the address of the function
printf("Address of the 'add' function: %p\n", (void *)add);


// Print the address stored in the function pointer
printf("Address stored in the function pointer: %p\n", (void *)funcPtr);


// Access and print the first few bytes of the function
printf("Bytes of the 'add' function:\n");
for (int i = 0; i < 20; ++i) {
printf("%02X ", ((uint8_t *)funcPtr)[i]);
}


return 0;
}


/*
Address of the 'add' function: 0x55c1a3a9b169
Address stored in the function pointer: 0x55c1a3a9b169
Bytes of the 'add' function:
F3 0F 1E FA 55 48 89 E5 89 7D FC 89 75 F8 8B 55 FC 8B 45 F8

Address of the 'add' function: 0x55beeff88169
Address…

--

--

Mi'kail Eli'yah
Mi'kail Eli'yah

No responses yet