void* foo(void* bar);
I know that the asterisk technically belongs with the variable name when declaring it, but it helps to wrap my head around them, as a reminder that they're a pointer type.
void* foo(void* bar);
I know that the asterisk technically belongs with the variable name when declaring it, but it helps to wrap my head around them, as a reminder that they're a pointer type.
A couple of code examples:
https://github.com/apache/httpd/blob/trunk/server/provider.c
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux....
Almost all documentation, references and literature: Here are a couple of man pages.
http://man7.org/linux/man-pages/man3/gethostbyname.3.html
https://developer.apple.com/library/mac/documentation/Darwin...
Here is a draft of the ISO C standard:
void *s = then use it as
s=
But I agree more that the void* s = then use it as
s=
Is more understandable as the first set confuse me when I learn pointer. It still does. void* is a type like statement. And void is like a return type statement. int *foo;
makes more sense, because to access the int, you write: *foo = ...;
But that's not an int, it's a crash! If you want an int, you have to make one.Placing the asterisk next to the type made it all click for me.
double foo;
compute(foo);
That's not even a crash, just silent garbage.I don't know how you expect to do better with an uninitialised variable (except ints that default to 0).
foo dereferences to an int, but what could you hope to happen if you never gave it some memory to point to?
int* s1, s2;
here s2 is an int, not an int* and you have to do int* s1, *s2;
this is braindead imho typedef void (*sighandler_t)(int);
sighandler_t signal(int signum, sighandler_t handler);
can be rewritten as typedef void sighandler_t(int);
sighandler_t *signal(int signum, sighandler_t *handler);