Skip to main content
Visitor II
December 12, 2018
Question

STM8 Cosmic: "weak" function

  • December 12, 2018
  • 3 replies
  • 961 views

Hello!

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

    This topic has been closed for replies.

    3 replies

    Visitor II
    December 12, 2018

    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.

    December 12, 2018

    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 =(

    Visitor II
    December 12, 2018

    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.

    Visitor II
    December 28, 2018

    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...