Switch with more decisions

Post here to discuss any new features, components, chips, etc, that you would like to see in Flowcode.
mnfisher
Valued Contributor
Posts: 1453
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 135 times
Been thanked: 707 times

Re: Switch with more decisions

Post by mnfisher »

A simple (rather contrived) example.

As Steve mentions - simulation is really not happening here.

There are some advantages over switch statements (at least for lots of options) - the code is smaller and the options run in constant time.
It also 'forces' the code to be split into multiple small macros rather than one large 'do-it-all' macro - which makes for more readable code.

I used an Arduino Nano - which has limited memory - so I can use 16 bit 'pointers'. If the MCU you are using has a larger address space JumpTable needs to be 32 bit. On the esp32 in might be necessary to 'cast' the macro address (FCM_Name) to a MX_UINT32 i.e. FCL_JUMPTABLE[0] = (MX_UINT32)FCM_Name;

One thing demonstrated here is the check on a option being defined - if(fn) - you can have a sparse table if needed.
I don't demonstrate passing arguments (or returning a result) - but it is certainly possible.


Martin
Attachments
Jump.fcfx
(12.59 KiB) Downloaded 151 times

S_VE
Posts: 26
Joined: Tue Jan 26, 2021 6:10 am
Has thanked: 32 times
Been thanked: 1 time

Re: Switch with more decisions

Post by S_VE »

Thank You Martin
S_V

Post Reply