Discussion:
[Sdcc-user] overloading functions (weak)?
Georg Icking-Konert
2017-05-06 05:55:35 UTC
Permalink
hello all,

apparently it is possible to overload functions in SDCC for STM8, as
shown recently in the getchar() implementation in one of the previous
mails. Is this something that can also be done with C routines in a
project? If yes, is there something like a "__weak" attribute to tell
the linker which function to use?

Thanks a lot in advance!

Regards, Georg
Maarten Brock
2017-05-06 08:13:08 UTC
Permalink
Post by Georg Icking-Konert
hello all,
apparently it is possible to overload functions in SDCC for STM8, as
shown recently in the getchar() implementation in one of the previous
mails. Is this something that can also be done with C routines in a
project? If yes, is there something like a "__weak" attribute to tell
the linker which function to use?
Thanks a lot in advance!
Regards, Georg
Hello Georg,

'Overloading' can only be done for functions that reside in a library. The
linker will first link all sources (actually .rel files a.k.a. objects) it
was given and after that it will search missing symbols in the libraries.
So if you provide getchar() in your sources there is no need to search for
it in the libraries and yours will be used.

This also means that all code in your object files is linked in whether
it's used or not. And objects in the libraries that are not referenced are
not linked in. Also note that all functions in an object are linked in,
not just the missing one.

Maarten

Loading...