So I made a simplification, however, if you start using C++ features such as OOP and advanced OOP then my statement is correct. You could the the equivalent in C but it's just messy. Now this is still a bit generalized and not always true so I shouldn't have generalized that much and it's a bit misleading but meh... And well try doing:
void* test = 1;
int* test2 = (int*)test; // This will not compile
int* test3 = static_cast<int*>(test); // Probably will compile.
Just one little nit pick, not really worth a mention in retrospect.
I apologize for not being able to explain in appropriate detail. I had a seizure a couple hours ago and am still in recovery. I did at least want to respond since I don't want others getting confused when they come across it.
void* isn't used that way.
#include <iostream>
int main(void) {
void *t1 = 1;
int *t2 = (int*) t1;
std::cout << *t1 << " : " << *t2 << std::endl;
return 0;
}
$ g++ -Wall -Wextra -W -ansi -pedantic -o cast_test{,.cpp}
cast_test.cpp: In function 'int main()':
cast_test.cpp:4:13: error: invalid conversion from 'int' to 'void*' [-fpermissive]
cast_test.cpp:7:16: error: 'void*' is not a pointer-to-object type
The error obviously points to the improper void* use. Better usage below.
#include <iostream>
int main(void) {
int t0 = 100;
void *t1 = &t0;
int *t2 = (int*) t1;
std::cout << *((int*) t1) << " : " << *t2 << std::endl;
return 0;
}
This casting is the same between both C and in C++. There is no difference just because STL gives us static_cast, dynamic_cast, const_cast, etc. C++ just gives more options, per usual.
Traditional use below.
#include <iostream>
void* func(void);
int main(void) {
int *t1;
t1 = (int*) func();
std::cout << *t1 << std::endl;
return *t1;
}
void* func(void) {
static int test = 125;
return &test;
}
C++ will do classic void* casting just like C. There is no change, you just didn't do it right.
--
Now that I have a little more clarity, I'd like it to be known that I have the utmost respect for bluechill so comments like "you schooled him even after a seizure" are not welcome. bluechill is a trusted and competent member of our staff and should be respected as such. Not everyone can know everything and I myself have consulted bluechill for assistance more than once.