Skip to content

Instantly share code, notes, and snippets.

@rambo
Created March 16, 2018 09:29
Show Gist options
  • Save rambo/3c4b98a9e37c068f9edeb5d53cc08eba to your computer and use it in GitHub Desktop.
Save rambo/3c4b98a9e37c068f9edeb5d53cc08eba to your computer and use it in GitHub Desktop.
reminder to self on how to deref void pointer to integer
// gcc -Wall void_ptr.c -o void_ptr ; ./void_ptr
#include <stdio.h>
#include <stdint.h>
void muck_count(void* param)
{
uint8_t *foo = (uint8_t*)param;
printf("foo %u\n", *foo);
*foo = 0;
}
int main()
{
uint8_t count = 0;
count = 10;
printf("Count before %u\n", count);
muck_count(&count);
printf("Count after %u\n", count);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment