+ 3
void* as argument in function
Had someone suggest using void *context in a function, statement was the function doesn't need to know anything about the variable being passed. In the particular call. I changed some code from: fun(type name); to fun(void *context); How does this optimize or make the program better? https://code.sololearn.com/cCctvUp8qtMf
1 Antwort
+ 6
Not sure about optimization or whether `void*` makes a program better. Just as I understand it, we pass a `void*` to a function to sort of "imitate" the polymorphism principal, in that we can use various types of data inside the function, we just need to dereference and cast the `void*` properly to a variable (of the actual type) we want to work with.
Actually, I'm not sure what benefit `void*` brings in this case, cause it seems that `float` be the only type that was used by the functions which uses `void*` parameters ...