Compiler Error 167

argument of type <type1> is incompatible with parameter of type <type2>

This error means that you are calling a routine which takes a parameter of type2 but you are passing in a variable of type1.

Example:

#include "mbed.h"

// Function which takes a pointer to a char* buffer.
void BufferRead(char* pBuffer)
{
    *pBuffer = 'h';
}

int main() 
{
    void* pvBuffer = malloc(42);

    // Calling BufferRead with a void* pointer instead of a char* pointer.
    BufferRead(pvBuffer);   // *** This is the line which generates the error. ***
    
    return 0;
}

This code would generate the following error for the line flagged in the example.

argument of type void* is incompatible with parameter of type char*

The solution in this case is to cast the void* pointer to type char* as in the following snippet:

    BufferRead((char*)pvBuffer);    

This error could occur in C code which is ported to the mbed cloud compiler as it always compiles source code as C++. In C, the compiler will automatically cast a void* pointer to char* but C++ enforces stricter type checking and generates this error.

The error may also be encountered if you have passed the parameters in the wrong order.


All wikipages