This is comment for paste
Recursive Kernel
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void handle_open_port(unsigned int x);
- void handle_close_port(unsigned int x);
- unsigned long previous_x = 0;
- void kernel_recursion(unsigned int x) {
- unsigned int current_previous_x = *(unsigned int *)((unsigned long)previous_x);
- //printf("PREVIOUS_X: %u ADDRESS: %ld CURRENT_ADDRESS: %ld\n", current_previous_x, previous_x, (long)&x);
- previous_x = (unsigned long)&x;
- if (x < current_previous_x) {
- handle_open_port(x); ++x;
- kernel_recursion(current_previous_x);--x;
- handle_close_port(x);
- } else if (current_previous_x < x) {
- handle_open_port(current_previous_x);
- kernel_recursion(current_previous_x + 1); --x;
- handle_close_port(current_previous_x);
- } else {
- handle_open_port(current_previous_x);
- handle_close_port(current_previous_x);
- }
- }
- void kernel(unsigned int x) {
- previous_x = (unsigned long)&x;
- kernel_recursion(0);
- }
- int main() { kernel(10); }
- void handle_open_port(unsigned int x) { printf("OPENING: %u\n", x); }
- void handle_close_port(unsigned int x) { printf("CLOSING: %u\n", x); }
Advertisement
Add Comment
Please, Sign In to add comment