Skip to main content
Mike xx
Associate III
May 16, 2024
Solved

Assign a variable to the c-file line number.

I have a FreeRTOS queue with many calls from various tasks.

I would like to assign elements of a variable that is passed into the queue with the file name and line number of the task that is placing the variable on the queue.

I have a corruption issue that might be a stack or perhaps an array that is being sent to the queue that is not copied but sent as a reference?

At the moment I have started to hand code the line numbers, but it's not ideal.

Can anyone help?

    This topic has been closed for replies.
    Andrew Neil
    Andrew NeilBest answer
    Super User
    May 16, 2024

    __FILE__ and __LINE__

     

    https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html

     

    EDIT:

    GCC also provides __FILE_NAME__ to give just the name, without path:

    https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.

    3 replies

    Andrew Neil
    Andrew NeilBest answer
    Super User
    May 16, 2024

    __FILE__ and __LINE__

     

    https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html

     

    EDIT:

    GCC also provides __FILE_NAME__ to give just the name, without path:

    https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Mike xx
    Mike xxAuthor
    Associate III
    May 16, 2024

    Many thanks for the quick reply.

    My previous google searched had failed me. I hadn't search with gnu or gcc.

    I thought they must exist as they do for the IAR compiler.

    Andrew Neil
    Super User
    May 16, 2024

    You're welcome.

    Yes, they are part of the C Standard - apart from __FILE_NAME__

    If that's answered the question, please mark the solution.

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.