Skip to main content
Dec 12, 2018 11:03 AM UTC
Question

STM8 Cosmic: "weak" function

Hello!

The Cosmic compiler supports "weak" functions to override them in the future?

    This topic has been closed for replies.

    4 replies

    AvaTar
    Senior III
    Dec 12, 2018 12:32 PM UTC

    Yes.

    Not limited to the "Cosmic" compiler, a label defined as "weak" might appear twice in a project.

    In other words, the label can appear once, or twice with one occurence defined as "weak". In the latter case, the non-weak definition takes precedence.

    This is e.g. used to supply default implementation for interrupt handlers.

    Dec 12, 2018 1:42 PM UTC

    Thanks for the answer!

    As a matter of fact, I wanted to find the syntax [weak] for STVD / Cosmic for STM8. The CXSTM8 documentation did not find this =(

    AvaTar
    Senior III
    Dec 12, 2018 2:06 PM UTC

    I did a project for a STM8 several years ago, with another toolchain (forgot its name ...).

    Not sure who "invented" it, but the "weak" attribute is supported by all gcc-based toolchains for ARM/Cortex M, and AFAIK also the Keil and IAR one's.

    The "weak" support includes the assembler and linker as well.

    S.Ma
    Principal
    Dec 28, 2018 6:40 AM UTC

    weak should be used when there is no other implementable way, because it is like a pandora box. You mayl see it as making your life easier at first...