Presentation is loading. Please wait.

Presentation is loading. Please wait.

Inline Functions Sometimes you need the same piece of code at multiple places in your task. Inline functions are copied at each place they are used. In.

Similar presentations


Presentation on theme: "Inline Functions Sometimes you need the same piece of code at multiple places in your task. Inline functions are copied at each place they are used. In."— Presentation transcript:

1 Inline Functions Sometimes you need the same piece of code at multiple places in your task. Inline functions are copied at each place they are used. In a sense, they are like #define, but they copy a block of code. There is no limit on the number of inline functions you can define.

2 void turn_around() { OnRev(OUT_C); Wait(340); OnFwd(OUT_A+OUT_C); } The name of the function is turn_around void indicates that it is an inlife function. task main() { OnFwd(OUT_A+OUT_C); Wait(100); turn_around(); Wait(200); turn_around(); Wait(100); turn_around(); Off(OUT_A+OUT_C); } The compiler will copy the code above each time the call to the inline function appears in a task.

3 void turn_around(int turntime) { OnRev(OUT_C); Wait(turntime); OnFwd(OUT_A+OUT_C); } An inline function can pass a value to the block of code. Instead of () use (int variable). This will define turntime within the function and allow you to pass different values to the function. task main() { OnFwd(OUT_A+OUT_C); Wait(100); turn_around(200); Wait(200); turn_around(50); Wait(100); turn_around(300); Off(OUT_A+OUT_C); }


Download ppt "Inline Functions Sometimes you need the same piece of code at multiple places in your task. Inline functions are copied at each place they are used. In."

Similar presentations


Ads by Google