3 ms·
Yes, casting in general is a code smell. (Not as in never use it, but as in use it as less as possible of course.) The thing is, void was introduced exactly t
by 1718627440 1y ago
Yes, casting in general is a code smell. (Not as in never use it, but as in use it as less as possible of course.)
The thing is, void was introduced exactly to represent this use-case without casting. The type to represent random amount of bytes, check which type and then cast is called char *. void * is for when you know exactly which type it has you just need to pass it through a generic interface, which isn't supposed to know or touch the type. The other use case is for when the object hasn't a type yet, like from malloc.
Previously everything was typed char *, then void * was used to separate the cases: casting from char *, don't cast from void *. Now in C++ both are the same again.