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

is there inline funtion in keil c51

i want to use inline function like in
c++ language.
how to do in keil c or it's not support?
use #define to simulate ?

  • It's not supported.

    However, some of the optimisation options in v6.14 might help?

    If you do use #defines, be very careful about all the pitfalls - especially parenteses, side-effects, etc
    Check the discussion in K&R!
    It would probably pay you to inspect the preprocessor listing carefully to ensure that you're actually getting what you intended.

  • However, some of the optimisation options in v6.14 might help?
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    Sorry, I dont know what you mean.
    Do you mean that the compiler will
    let functions that be called only
    once become inline functions automatically?
    if yes, how to set this option?

  • I don't think it goes that far, but look at Level 8, Common-Tail Merging, and Level 9, Common-Block Subroutine Packing.
    Note that enabling an optimisation level automatically includes all the lower levels.

    (I presume your emphasis would be "Favour Code Size?")

    If your function is only ever called once, does it really need to be a function?
    A function might be better for "style," but optimisation seems to be your overriding concern? In this case, it's OK to sacrifice "style" so long as it's well justified and all clearly documented

  • Thanks for your answer.
    My point is readable code. for example:

    switch x {
    case 1: f1();
    case 2: f2();
    .....

    it's more clear than not using function.

    but i'm afraid to call too much level,
    the stack memory overflow. especially in
    interrupt function.

    Maybe I should try another programming style.