Last active
March 27, 2023 23:23
-
-
Save pavly-gerges/dd327e9e8e9dfed1ea06e76de56b9f42 to your computer and use it in GitHub Desktop.
Test void* to jlong implicit type-conversion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
/* define a non-system-specific pointer type that can hold an address of up-to 8-bytes */ | |
typedef long long jlong; | |
jlong Java_util_getAddress() { | |
int* x = malloc(sizeof(int)); | |
*x = 2312; | |
void* address = x; | |
return address; | |
} | |
int main() { | |
int* ptr = ((int*) Java_util_getAddress()); | |
printf("%lld\n", *((int*) Java_util_getAddress())); | |
printf("%lld\n", *((int*) Java_util_getAddress())); | |
free(ptr); | |
printf("%lld\n", *((int*) Java_util_getAddress())); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment