dani007200964 / Commander-API

Commander-API is a simple to use C++ parser library and you can easily use it to process character based commands
MIT License
24 stars 4 forks source link

Refactor use of F() macro to simplify `#ifdef`s #20

Closed ondras12345 closed 1 year ago

ondras12345 commented 1 year ago

This should make the code more readable with no change at all to the compiled binary. It should also make it easier to change these string literals in the future as there are no longer multiple occurrences that need changing.

The name of the new macro FF() is arbitrary, I just thought it should be short.

I also removed some unnecessary casts of string literals to const char *.

I was unable to test Commander-API-Commands because they seem to be broken at the dev branch.

error: invalid conversion from 'void (*)(char*, Stream*)' to 'void (*)(char*, Stream*, void*)' [-fpermissive]
dani007200964 commented 1 year ago

Thank you! Really good idea, I like it. Tonight maybe I will have some time to close this PR.

ondras12345 commented 1 year ago

I think I will create a dedicated function for this line: response -> print( FF( "Argument error!" ) );

I don't think that's necessary. The compiler will most likely merge identical string literals. If it doesn't inline your function, it might actually increase code size. But feel free to try it. I'd ensure that the string is always the same, for example with something like this:

#define COMMANDER_ARGUMENT_ERROR "Argument error!"

But that should be sufficient.