This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Why IAR throw Error[pe167] on void*

Other Parts Discussed in Thread: EK-TM4C123GXL

Hello.

I don´t know how to solve this error.

I´m try to compile (under IAR ARM 7.5 /  with EK-TM4C123GXL), a USB CDC application.  


This was successful using the C compiler , but now I need to compile it with c ++ .

And so my application as the example project " usb_dev_serial "  show compilation error :

Error[Pe167]: argument of type "void *" is incompatible with parameter of type "tLineCoding *" .......\TivaWare\examples\boards\ek-tm4c123gxl\usb_dev_serial\usb_dev_serial.c 852.

to replicate the problem, I  just change under IAR Compiller from C to C++.

Regards

Fernando

Code

uint32_t
ControlHandler(void *pvCBData, uint32_t ui32Event,
               uint32_t ui32MsgValue, void *pvMsgData)
{
    uint32_t ui32IntsOff;

    //
    // Which event are we being asked to process?
    //
    switch(ui32Event)
    {
        //
        // We are connected to a host and communication is now possible.
        //
        case USB_EVENT_CONNECTED:
            g_bUSBConfigured = true;

            //
            // Flush our buffers.
            //
            USBBufferFlush(&g_sTxBuffer);
            USBBufferFlush(&g_sRxBuffer);

            //
            // Tell the main loop to update the display.
            //
            ui32IntsOff = ROM_IntMasterDisable();
            g_pcStatus = "Connected";
            g_ui32Flags |= COMMAND_STATUS_UPDATE;
            if(!ui32IntsOff)
            {
                ROM_IntMasterEnable();
            }
            break;

        //
        // The host has disconnected.
        //
        case USB_EVENT_DISCONNECTED:
            g_bUSBConfigured = false;
            ui32IntsOff = ROM_IntMasterDisable();
            g_pcStatus = "Disconnected";
            g_ui32Flags |= COMMAND_STATUS_UPDATE;
            if(!ui32IntsOff)
            {
                ROM_IntMasterEnable();
            }
            break;

        //
        // Return the current serial communication parameters.
        //
        case USBD_CDC_EVENT_GET_LINE_CODING:
            GetLineCoding(pvMsgData);
            break;

...

...

  • C is more forgiving of type mismatches.

    The code is potentially wrong in both languages. Although the syntax is correct in C, I would flag it as wrong as well but I'm quite particular.

    The problem is that pvMsgData is a void pointer and GetLineCoding expects a tLineCoding pointer. That is a type mismatch. Even in C it's generally considered an unsafe practice to pass a void pointer where a pointer to a specific type is asked for.

    The proper way to fix this normally is to change the type passed to ControlHandler to tLineCoding. You can use casting but that is likely to cause problems later.

    There are other ways to fix it. Some of them would involve a re-design of your function so that it is properly typed. I have found over the years that if you are having trouble keeping your types consistent it usually indicates a fundamental design flaw.

    Robetr
  • Robetr , thanks for the prompt response. The proposal to fix solved through casting type, It's like you say brings problems or more problems later (I've already tried).

    I drew attention because this code is provided in Tivaware .

    Hurts , my c ++ project will continue without USB CDC , because I do not have time to learn about USB .

    Thanks a lot .
    Fernando