This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

changing whitespace in code is causing compile error

when a particular line of my code is at line 54, the following compile error occurs: error: #101: "assert_line_54" has already been declared in the current scope

line 54 is where the error is occurring according to the compiler - it's a declaration of a variable to contain ESB payload data: nrf_esb_payload_t tx_payload = NRF_ESB_CREATE_PAYLOAD(0, 0x00, 0x00);

Adding or removing a line of whitespace before line 54 removes the compile error, and so does removing the NRF_ESB_CREATE_PAYLOAD, but I have no way of knowing whether this is due to a compiler bug or that there is an actual error in the code that is escaping detection. Why is this error occurring? NRF_ESB_CREATE_PAYLOAD makes use of STATIC ASSERT in esb.h, making use of static_assert_ or assert_line in app_util.h depending on whether COUNTER is defined in the SDK files. Keil reports static_assert- and assert_line are undefined, which I doubt however this means the trail ends there.

I include the standalone project folder where this can be reproduced: open standalone_project\projects\esbRX_SPIS\project\pca10040\arm5_no_packs\project_pca10040.uvprojx . I have removed all functions save for an empty main(). If the aforementioned line is at line 54, the error occurs, but not on any other line as far as I can tell.

Attachment: standalone_project.zip

Parents
  • Hi Adrien,

    I think I have found the cause of the compiler error you're getting and I will try to explain it. So, a static assert has been placed at line 54 in nrf_esb.h . The macro NRF_ESB_CREATE_PAYLOAD also contains a static assert. The static asserts are defined as follows in the SDK

    #define STATIC_ASSERT(EXPR) \
        ;enum { STRING_CONCATENATE(assert_line_, __LINE__) = 1/(!!(EXPR)) }
    

    i.e. it refers to a specific line number. So placing

    static nrf_esb_payload_t tx_payload = NRF_ESB_CREATE_PAYLOAD(0, 0x00);
    

    at line 54 in main() will lead to two static asserts referring to the same line number in both main.c and nrf_esb.h which is included in main.c. I do not know enough about the compiler to tell you exactly why this causes it to freak out, but at least you know the cause now.

    Best regards

    Bjørn

Reply
  • Hi Adrien,

    I think I have found the cause of the compiler error you're getting and I will try to explain it. So, a static assert has been placed at line 54 in nrf_esb.h . The macro NRF_ESB_CREATE_PAYLOAD also contains a static assert. The static asserts are defined as follows in the SDK

    #define STATIC_ASSERT(EXPR) \
        ;enum { STRING_CONCATENATE(assert_line_, __LINE__) = 1/(!!(EXPR)) }
    

    i.e. it refers to a specific line number. So placing

    static nrf_esb_payload_t tx_payload = NRF_ESB_CREATE_PAYLOAD(0, 0x00);
    

    at line 54 in main() will lead to two static asserts referring to the same line number in both main.c and nrf_esb.h which is included in main.c. I do not know enough about the compiler to tell you exactly why this causes it to freak out, but at least you know the cause now.

    Best regards

    Bjørn

Children
  • Many thanks for your answer Bjorn, it makes it clear enough for me though I don't know exactly why the compiler is freaking out about this. My best guess is it doesn't make the difference between the different files. I hadn't been aware of line-number-dependent commands for compilers before, so this is a first for me. I also hadn't noticed the static assert in esb.h was placed at the same line, many thanks for catching that.

Related