I am having an issue where I have a C2440 error when compiling a C++ project in VS2005. The error is due some existing C code in another project which I depend on which casts a void pointer to either a char or int pointer.
The code resembles:
void * bbb;
... // some code which defines the void pointer
int * aaa = bbb;
However in C++ I need to specifically cast the type to be valid such as:
int * aaa = (int *)bbb;
My question is whether there exists a flag or compile option in VS2005 which allows my to compile my main project in C++ and ignore this error from depending projects I want to compile as C?
I would rather not change any of the original source as it is a shared project.
If you name the file "something.c", the compiler will [unless explicitly told otherwise] compile it as C (and thus happily accept your pointer conversion without using a cast). A file named "something.cpp" will be compiled as C++, and you will need a cast to convert a pointer to a different type, even if it's a void pointer.
The only way to do this was to edit the header files which caused the problem. It turned out to be a minor number of files which could be merged back into the shared projects.
There is no way to get around this in VisualC++. I had used -fpermissive to ignore the error in gcc.
So I just made the update to:
int * aaa = (int *)bbb;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With