Most of my posts on this forum are along the lines of 'how do I fix this...'. This one is different, I've actually fixed the problem but I'd now like to know why my original method wouldn't work.
In one of my libraries I've defined this value....
#define max_chars 150
Which I occasionally need to use elsewhere. This is my original (very simple) function that doesn't work....
inline byte getWidthx(){return (byte)max_chars;} // Get the maximum width of messages in the stack
And this is my new improved version that does work.
/**************************************************************************
// Get the maximum width of messages in the stack
**************************************************************************/
byte MiniStack2::getWidth()
{
return (byte)max_chars;
}
To my mind they appear to be identical. However, when I call them from another library like this....
If nothing changes, use the original and declare _maxMessLen as volatile. Maybe nothing will change, but it would be interesting to see.
It also looks like you are using an outdated arduino IDE version.
I can't do that, _maxMessLen is used to define the length of some character strings so needs to be declared up front.
looks like you are using an outdated arduino IDE version.
Yes, I'm using version 21. I'm working on the principle that unless there's a positive need for an upgrade I'd prefer not to risk the possibility of an 'upgrade hell'
Thanks for the suggestions. Sometimes it's re-assuring when I don't get flooded with a deluge of posts pointing out an obvious error - at least it means I'm not as stupid as I thought.
Can you explain how the call to EventManStack->getWidthx() works? The definition you showed seems to be a regular function and not a class method, so perhaps there is something else going on that we have overlooked.
Preferably, reduce your big complex sketch to a minimal test case that shows this specific behaviour and then post the whole of it.
I'm trying to cut the code down to a couple of stripped-down libraries to post here. In the meantime here's some more details.
max_chars and non-functioning function getWidthx() are defined in the file MiniStack2.h. The working function getWidth() is defined in MiniStack2.cpp
I have then used the MiniStack2 library to create a singleton version of this library called sMiniStack2
I have a 2nd library called EventManager, which uses a singleton object from the sMiniStack2 library.
Finally I have a test sketch that creates an EventManager object (which in turn creates a singleton version of MiniStack2) and then invokes EventManager.begin() to give the results previously shown.
Strangely, I seem to be capable of writing code that once I've written I have trouble understanding myself!