This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

error while compiling pstorage.c

hello, Please forgive me if I am asking a stupid question.

I was editing S130 demo app and I included pstorage.c file to the project. while compiling it is showing error saying "declaration may not appear after executable statement in block".

void pstorage_sys_event_handler(uint32_t sys_evt)
 {
      uint32_t retval = NRF_SUCCESS;

if (m_cmd_queue.flash_access == true)
{
...............................
...............................

    switch (sys_evt)
    {
        case NRF_EVT_FLASH_OPERATION_SUCCESS:
        {
            .......

           const bool store_finished =
                ((p_cmd->op_code == PSTORAGE_STORE_OP_CODE) &&
                 ((m_round_val * SOC_MAX_WRITE_SIZE) >= p_cmd->size));      /* Here i am getting error*/

           const bool update_finished =
                ((p_cmd->op_code == PSTORAGE_UPDATE_OP_CODE) &&
                 (m_swap_state == STATE_COMPLETE));

            const bool clear_block_finished =
                ((p_cmd->op_code == PSTORAGE_CLEAR_OP_CODE) &&
                 (m_swap_state == STATE_COMPLETE));

              ...........
              ...........

The declaration of const bool variable is done after some executable part. How it is possible in C? I got the same error for some other source files also. The pgm works fine for S110. Then what could be the possible problem with S130??

Thanks in advance.

Parents
  • Hi there,

    c99 standard allows declarations after executable block of code. If you turn on c99 mode in your compiler (in Keil, you will find this option under 'Project'->'Options for ...'->'C/C++'), you will do away with this error.

    The S110 projects that come with the SDK have c99 mode turned on by default. That is why you do not get the error when compiling them.

    Cheers, Balaji

Reply
  • Hi there,

    c99 standard allows declarations after executable block of code. If you turn on c99 mode in your compiler (in Keil, you will find this option under 'Project'->'Options for ...'->'C/C++'), you will do away with this error.

    The S110 projects that come with the SDK have c99 mode turned on by default. That is why you do not get the error when compiling them.

    Cheers, Balaji

Children
No Data
Related