How do I create a weak function via Keil Cx51?
Have you taken a look through the options available?
http://www.keil.com/support/man/docs/c51/
I don't recell there being such an option, but then I'd never felt the need for it - why do you feel the need for it?
Yes, But I can't find any information I can use. I want to create a function like putchar() that the user can modify if they need.
Weak functions look like a useful feature of a toolchain, but they are actually not - really. I have seem them being abused by so many who considered themselves are "developers", only to produce unmaintainable, unbeliable junk code. In other words: don't.
So just provide it as source - then the user can modify/replace/remove that source as required.
Or provide it in a library (a true pre-built library) - the linker will only take stuff from the library that is otherwise undefined ...
Note that a "WEAK" attribute just allows the user to completely replace the function - it does not help if the user wants to keep the function, but just modify it ...
Thanks for your suggestion. However, it would release the function description instead of the source code to the user because of the application issue.
For example, it would have a prototype hook function with the arguments, and then the system handling will depend on the result of the return. The user would create the hook function for themselves need.
If you really want to do it, then an alternative might be to simply have your code module contain a function to set a callback function pointer and call that function if (for example) non-null. OK, pointers in C51 aren't very efficient, but I suspect your application doesn't go for being ultra efficient.
View all questions in Keil forum