3 ms·
The example just shows some of the functions for the library being used. Mainly the storing and returning of values. As for the numbers like "(void*)0xcafe" it'
by anfilt 4y ago
The example just shows some of the functions for the library being used. Mainly the storing and returning of values. As for the numbers like "(void*)0xcafe" it's casting the number 0xcafe (in hex) to a void*. Why those constants they just easy to read in hex since they happen to spell a word. They could be anything, depending on your application like a pointer to data or some important constant ect...
- qprofyeh 4y agoThanks, so void* is the any type in C. And the argument is not necessarily a pointer nor should it be dereferenced. I think I understand.
- Warwolt 4y agoMore particularly, I would describe it as a "pointer to anything". The size of the value will be exactly the size used for pointers in the given system (e.g. 8 bytes). If you happen to know what a void* is pointing to, you can cast it to another type like "my_struct_t*" and deference the value. I would call it a work around for C lacking true polymorphism.
- quietbritishjim 4y agoThat is pretty much the opposite of what GP said: they're using void* to directly store an integer value rather than a pointer to anything (in that case).