Definitely not. Polymorphism happens when the compiler does stuff for you under the hood and you as a developer just have to understand the idea of it to get it to work. Use of void* on the other hand requires you as a developer to write the code yourself and also understand the idea of polymorphism to get it to work right.
It can be *part of* polymorphism I guess
polymorphism is still polymorphism when done manually
How’d u define polymorphism in C/Cpp?
unbounded dynamic dispatch
Psudocode?
struct MyInterface { void *data; void (*doThing)(void *); } x->doThing(x->data);
This is exactly what I had in mind
with bounded you can use a tagged union
Not sure what u mean by bounded
How many possible different kinds of things are there?
Something like traits in Rust?
How many different types you mean?
This can be like: "4" "I'll add like 10-ish, but I'll know at compile time" "It's a plugin system, so it's only known at runtime, however many plugins the user needs to load"
I call it downcasting.
Polymorphism as a concept defines subtyping which by definition is not something that is allowed in C. So you can't then say using void* pointers to simulate subtyping is polymorphism in the strictest sense. As long as a language does not support subtyping, it can't be called polymorphism. Moreover using void* pointers to cast from one type to another unrelated type is Undefined Behavior according to the C standard. So even if you see the behavior you expect on your implementation, it is not guaranteed to happen across all implementations. So this behavior is indeed undefined behavior and is therefore no where close to the idea of polymorphism
But you're never casting from one type to another
https://en.m.wikipedia.org/wiki/Polymorphism_(computer_science)
I'm not talking about subtype polymorphism
For one of these you need unbounded
Обсуждают сегодня