Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

conflicting types for '_putchar'

Hello,

There's a problem compiling the standard ble_app_uart_pca10040_s132 in Segger Embedded Studio for ARM V3.40.  The UART example is straight out of nRF5_SDK_14.2.0_17b948a.

The exact same example can be compiled OK in SES V3.34.

The error message in V3.40 is 

conflicting types for '__putchar'

retarget.c

previous declaration of '__putchar' was here

That line points to stdio.h declaration of __puchar

Parents
  • Hi Winston,

    SEGGER has added the prototype for _putchar() in stdio.h, but the declaration of this prototype has a different type of variable.

    See below: 

    stdio.h (line 773)

    // Macro version of putchar.
    #ifndef __PRINTF_TAG_PTR_DEFINED
    #define __PRINTF_TAG_PTR_DEFINED
    typedef struct __printf_tag *__printf_tag_ptr;
    #endif
    int __putchar(int, __printf_tag_ptr);
    #define putchar(x) __putchar(x, 0)
    

     

    Solution:

    To solve this issue, we need to change the type of value in __putchar to __printf_tag_ptr instead of FILE *.

    before: (retarget.c, line100)

    int __putchar(int ch, FILE * p_file)
    {
        UNUSED_PARAMETER(p_file);
    
        UNUSED_VARIABLE(app_uart_put((uint8_t)ch));
        return ch;
    }
    

    after:

    int __putchar(int ch, __printf_tag_ptr p_file)
    {
        UNUSED_PARAMETER(p_file);
    
        UNUSED_VARIABLE(app_uart_put((uint8_t)ch));
        return ch;
    }
    

Reply
  • Hi Winston,

    SEGGER has added the prototype for _putchar() in stdio.h, but the declaration of this prototype has a different type of variable.

    See below: 

    stdio.h (line 773)

    // Macro version of putchar.
    #ifndef __PRINTF_TAG_PTR_DEFINED
    #define __PRINTF_TAG_PTR_DEFINED
    typedef struct __printf_tag *__printf_tag_ptr;
    #endif
    int __putchar(int, __printf_tag_ptr);
    #define putchar(x) __putchar(x, 0)
    

     

    Solution:

    To solve this issue, we need to change the type of value in __putchar to __printf_tag_ptr instead of FILE *.

    before: (retarget.c, line100)

    int __putchar(int ch, FILE * p_file)
    {
        UNUSED_PARAMETER(p_file);
    
        UNUSED_VARIABLE(app_uart_put((uint8_t)ch));
        return ch;
    }
    

    after:

    int __putchar(int ch, __printf_tag_ptr p_file)
    {
        UNUSED_PARAMETER(p_file);
    
        UNUSED_VARIABLE(app_uart_put((uint8_t)ch));
        return ch;
    }
    

Children
Related