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

Attempted to compile SDK 17 with the c ++ compiler

Hi everyone, I have some problem with SDK 17, when I try compile it by C++ compiler.  Compiler detected many errors, for example:

  • nrf_fprintf,c problem with va_lista

va_list should never be initialized. It's standard in C and C++ that it is just left uninitialized until va_start() is called

  • ble_lbs.c (and many services example)

Problem wit missing assignament to variable VERIFY_SUCCESS(error_code);

     

  • nrf_atflags.h

Missing on top

#ifdef __cplusplus
extern "C" {
#endif

  • nrf_sdh.h, nrf_sdh_soc.h, nrf_sdh_ble.h

Problem with construction for example:

typedef struct
{
…….	
} const nrf_sdh_req_observer_t

I m not sure that construction with const is acceptable, please give me reason for using such a structure.

According to: https://en.cppreference.com/w/cpp/language/typedef

“The typedef specifier cannot be combined with any other specifier except for type-specifiers.”

  • Many files for example gatt_cache_manager.c

Problem with order inicjalization.

pm_evt_t event =
            {
                .evt_id      = PM_EVT_SERVICE_CHANGED_IND_CONFIRMED,
                .peer_id     = im_peer_id_get_by_conn_handle(conn_handle),
                .conn_handle = conn_handle,
            };

error: designator order for field ‘pm_evt_t::conn_handle’ does not match declaration order in ‘pm_evt_t’

According to: https://en.cppreference.com/w/cpp/language/aggregate_initialization

“The syntax forms (3,4) are known as designated initializers: each designator must name a direct non-static data member of T, and all designators used in the expression must appear in the same order as the data members of T.”

Parents
  • There are plenty of previous posts on this

    Nordic do not claim that the SDK is C++

    You can compile the SDK as C, and link to C++ code ...

  • Hi

    I think it some misunderstand in general.

    point some constructions what are at least doubt (but be honest possibly bug or for sure bug) not only related to C++ but also C.

    1. initialize instance of va_list by 0?? it is not related to C++

    2. macro VERIFY_SUCCESS return value in context of function void??

    3. I know it is not stack-overflow when we may ask general programming question but could you refer to key word "const" in construct quoted below? is it valid according any C standard?

    In my opinion it us quite odd/uncommon so if you point me paragraph in Ansi C standard what allow on it, I will appreciate. If not why nordic use such construct?

    typedef struct
    {
    …….    
    } const nrf_sdh_req_observer_t

    I think we may refactor this topic into kind of source code quality if you prefer in order to address some issue into nordic source code.

    Best Regards

    /Greg

Reply
  • Hi

    I think it some misunderstand in general.

    point some constructions what are at least doubt (but be honest possibly bug or for sure bug) not only related to C++ but also C.

    1. initialize instance of va_list by 0?? it is not related to C++

    2. macro VERIFY_SUCCESS return value in context of function void??

    3. I know it is not stack-overflow when we may ask general programming question but could you refer to key word "const" in construct quoted below? is it valid according any C standard?

    In my opinion it us quite odd/uncommon so if you point me paragraph in Ansi C standard what allow on it, I will appreciate. If not why nordic use such construct?

    typedef struct
    {
    …….    
    } const nrf_sdh_req_observer_t

    I think we may refactor this topic into kind of source code quality if you prefer in order to address some issue into nordic source code.

    Best Regards

    /Greg

Children
No Data
Related