This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to create a weak function in Cx51

How do I create a weak function via Keil Cx51?

Parents
  • "If the user needs to handle the event, then it needs to port the code in the function. otherwise, the user doesn't need to handle the event. they could do nothing about the function."

    Then having the default handler in a library (a true, pre-built, binary) would solve that - the linker will only take the function from the library if it isn't provided by the user.

    Providing it as source would also work - the user only has to touch the "default" source when they want to do specific handling.
    This is what you'd have to do anyhow with a "WEAK" attribute.

    A callback would also be possible but, as already noted, function pointers are problematic in C51.

Reply
  • "If the user needs to handle the event, then it needs to port the code in the function. otherwise, the user doesn't need to handle the event. they could do nothing about the function."

    Then having the default handler in a library (a true, pre-built, binary) would solve that - the linker will only take the function from the library if it isn't provided by the user.

    Providing it as source would also work - the user only has to touch the "default" source when they want to do specific handling.
    This is what you'd have to do anyhow with a "WEAK" attribute.

    A callback would also be possible but, as already noted, function pointers are problematic in C51.

Children
  • Then having the default handler in a library (a true, pre-built, binary) would solve that - the linker will only take the function from the library if it isn't provided by the user.

    How about C++ on a C51 :-)

  • "Then having the default handler in a library (a true, pre-built, binary) would solve that - the linker will only take the function from the library if it isn't provided by the user."

    Yes, I just want to create a library-like kernel. Then providing a function description like putchar() for users that can modify it if they want to. If users want to use the kernel I make, they just include the head file then they can use the function about the kernel. Because some kind of function in the kernel is necessary for the application. So the user couldn't allow renaming that functions. But if they want to do more things. They can create the function with the same function names, then modify it.