Skip to content

Instantly share code, notes, and snippets.

@polprog
Created January 17, 2018 23:04
Show Gist options
  • Save polprog/5d488f18b30dda3f0c8d3ec9981729cf to your computer and use it in GitHub Desktop.
Save polprog/5d488f18b30dda3f0c8d3ec9981729cf to your computer and use it in GitHub Desktop.
#include <stdio.h>
/********************
* Enterprise array handler
* (c) 2018 Polprog
*
********************/
//TODO: Rewrite in C++ as a class
void * getArrayElement(void * arr, char element, char elementSize){
return (void *)(arr + element*elementSize);
}
int main(){
char array[] = { 0, 2, 4, 5 };
char test = *(char *)(getArrayElement(array, 1, sizeof(char)));
printf("%d\n", test);
__uint64_t widearray[] = {0, 118, 999, 88199, 9119725};
printf("%d\n", *(__uint64_t *)(getArrayElement(widearray, 4, sizeof(__uint64_t)))); //sizeof in case of systems where uint64_t is not 4 bytes wide
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment