-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple FSM's in same program with colliding state names have unexpected side effects #41
Comments
The point is that under the hood TinyFSM will instantiate a As a workaround, try to put the code in each cpp-file into different namespaces, this might help. Another fix would be to make templates out of your state classes similar to the "multiple_switch" example [6], but this leads to very unreadable code and thus is kind-of discouraged. [1] https://github.com/digint/tinyfsm/blob/v0.3.3/include/tinyfsm.hpp#L71-L77 Ultimately it would be nice to have some simple example code to illustrate this problem on "vanilla gcc", after all this might be just some bug in your compiler suite; risc-v ftw, but the last time I played around with ESP32 (a couple of years ago) I abandoned it as everything in their ecosystem was closed source and badly documented... |
Ok, repeated it with my host gcc:
main.cpp:
one.cpp
two.cpp
Output is:
There is no warning here as-well. So it doesn't seem like a compiler issue. |
And placing it in separate namespaces, like:
... fixes it, which was to be expected. |
The problem is that you are violating the "One Definition Rule" (ODR) [1]. There is a [1] https://en.wikipedia.org/wiki/One_Definition_Rule In order to demonstrate this, I have added your example in the "one-definition-rule" branch:
So this is either a gcc bug, or for some reasons it is not possible to resolve ODR problems without LTO. Anyways I should place some warning in TinyFSM regarding this problem. |
OK, thanks for the clarification, I didn't know about ODR. I wonder if the FSM_INITIAL_STATE macro could explicitly 'associate' the passed state as being derived from the passed FSM and therefore hint template deduction? I'm not too deep into templates, though. |
Most probably I'm missing something trivial here, but I'm unable to understand what is happening in the following case:
This is the station FSM
And again for the AP FSM:
The trouble is, that the AP FSM start does not enter the Idle state. If I rename the states to APIdle and APStarted it works.
None of the state structs are defined in a header file, but solely in 'their' cpp files.
What am I missing?
BTW: This is an ESP32 project (IDF 5.2.1), riscv32-esp-elf-gcc (crosstool-NG esp-13.2.0_20230928) 13.2.0
The text was updated successfully, but these errors were encountered: