Page 2 of 2

Re: Macro calling

Posted: Wed Aug 26, 2026 10:23 am
by mnfisher
A few thoughts.....

I did a simple example - that allows macros with names 'A' to 'Z' - note that if you want to use lower case - you can either alter the call to .c - 'a' (instead of (.c - 'A')) - or convert the lower case letter to upper case.
I use a sparse array of 26 function pointers (0..25) - this could be extended (for example fn_table[128] then call fn_table['A']( ))

I added a small macro CallString that calls each character of a string passed as an argument in turn - there a couple of examples. Note that 'undefined' macros - are ignored (I threw an 'E' into one of the strings)
for example CallString("ABCDABCDZ") or CallString(.cmd_string)

The function table is initialised in supplementary code....

Code: Select all

typedef void (*function)();
function fn_table[26] = {
[0] = FCM_A,
[1] = FCM_B,
[2] = FCM_C,
[3] = FCM_D,
['Z' - 'A'] = FCM_Z};  // I handle 'A' to 'Z' as 0..25
It is necessary to get the addresses of the functions (Flowcode (C) is a compiled language and functions are called with 'call fn_address' at runtime (not call "function_name"))

I would recommend giving functions (and variables) meaningful names rather than single characters - but in this instance it is quicker to do it this way (storing a string of each function name and then searching would add overhead at runtime)

The function signature could be altered to allow arguments to be passed (or a value returned by the macros)

Martin

Re: Macro calling

Posted: Wed Aug 26, 2026 9:17 pm
by medelec35
Hi.
I have use a string array so you can use different string macro names rather than sticking to 1 character.
Flowchart does fully simulate.
I did nest them which made it look neater, but its more difficult to follow.
Un-nested decision branches just for the demo

Re: Macro calling

Posted: Sun Sep 20, 2026 9:45 pm
by alanwms
In the Command_list_String[0] = 'i' the letter "I" s the name of my macro. I was hoping to call macro "I" but the compiler tries to call macro FCL_i which does not work.
I just want to call macro "I"

Re: Macro calling

Posted: Mon Sep 21, 2026 5:35 am
by mnfisher
What code are you using? - both methods given above work as expected - can you post the fcfx file you are testing?

Martin

Re: Macro calling

Posted: Mon Sep 21, 2026 9:29 am
by Steve-Matrix
Thanks Martin, and Martin. Interesting examples.

You probably know this already, but or the @medelec35 project, you can use direct string comparisons in v11 - e.g. a decision with the following expression:

Code: Select all

.MacroTable[.Index] == "macro5"

This makes it a bit easier to read that the current expression:

Code: Select all

Compare$(.MacroTable[.Index], "macro5", 0) == 0