ILE C/C++ Programmer's Guide

Resolving Incompatible Pointer Types



C language only


C++ language only

In ISO C, a pointer to void can be assigned to a pointer of any other type. You do not need to cast the pointer explicitly. C++ allows void pointers to be assigned only to other void pointers. If you use C memory functions that return void pointers (such as malloc(), calloc(), realloc()), each void pointer must be cast to an appropriate pointer type before the code is compiled.
Note:
You can use the new and delete operators instead of malloc() and free().
The C compiler compiles source code that uses memcmp() to compare a constant char array to a volatile char array. When attempting to compile source code that uses memcmp() to compare a constant char array to a volatile char array, the C++ compiler generates an error message (for example, volatile unsigned char cannot be converted to a const void pointer). You cannot use a constant pointer where a volatile pointer is expected unless you cast a void pointer to the appropriate pointer type before compiling the code.
Note:
You can use the new and delete operators instead of malloc() and free().
Note:
See the WebSphere Development Studio: ILE C/C++ Language Reference for more detailed information on compatibility.


[ Top of Page | Previous Page | Next Page | Table of Contents ]