anna on Nostr: UsernameSwift ☭ :verifiedaroace: Phineas 'fossoid' Holstrom buy robux today :ROBUX: ...
UsernameSwift ☭ :verifiedaroace: (npub1zt2…ccgj) Phineas 'fossoid' Holstrom (npub1vhx…sekz) buy robux today :ROBUX: (npub1wg0…t0yf) you don’t need to cast any pointer to/from void pointers actually.
this is valid and generates no warnings with -Wall -Wpedantic -fanalyzer:
#include <stdio.h>
#include <stdlib.h>
struct nya {
int foo;
int bar;
};
void nya(void *mew) {
struct nya *meow = mew;
printf("%d, %d\n", meow->foo, meow->bar);
}
int main() {
struct nya foo = { .foo = 5, .bar = 10 };
nya(&foo);
return 0;
}
so not only malloc, realloc, and free, void* in general are exempt from casts
(but do remember strict aliasing rules. you can’t put a type into a void pointer, and then turn it into another type)
this is valid and generates no warnings with -Wall -Wpedantic -fanalyzer:
#include <stdio.h>
#include <stdlib.h>
struct nya {
int foo;
int bar;
};
void nya(void *mew) {
struct nya *meow = mew;
printf("%d, %d\n", meow->foo, meow->bar);
}
int main() {
struct nya foo = { .foo = 5, .bar = 10 };
nya(&foo);
return 0;
}
so not only malloc, realloc, and free, void* in general are exempt from casts
(but do remember strict aliasing rules. you can’t put a type into a void pointer, and then turn it into another type)