So, I am having a little trouble debugging something I'm writing for a Mega2560. What it is isn't really critical, but I tripped up over something I thought I understood, and obviously I don't.
To summarise I've effectively been adding code to my software to track functions/methods entering and leaving using a relatively simple class as a local variable (so I can use the constructor and destructor to catch the enter and leave actions. The constructor takes a "const char *" argument which is supplied with the value __PRETTY_FUNCTION__ so that it knows where it is.
Now, this all works fine at one level except that all these __PRETTY_FUNCTION__ values are placed into SRAM, and so I have now blown through the whole 8 KBytes of available memory.
No problem (I think to myself) I'll create a "static const char func[] PROGMEM = __PRETTY_FUNCTION__;" before the stack frame tracking variable, and pass this into it in place of directly using __PRETTY_FUNCTION__. Obviously I need to remember that now I need to use the address provided to pull the actual text from program memory rather than SRAM, but that's easy.
Or so I thought.
It seems that (upon some digging about) __PRETTY_FUNCTION__ isn't actually a text constant anymore, but a hidden (almost underhand) variable defined by the compiler on your behalf. As a result the following line of code does not compile:
static const char func[] PROGMEM = __PRETTY_FUNCTION__;
with an error something along the lines of "I can't work out how big the data is", but the following line does compile:
static const char func[] PROGMEM = "__PRETTY_FUNCTION__";
See the difference?
Obviously the second is functionally pointless from my perspective, but proves that I'm not being totally foolish (as I was beginning to believe).
So the question is "How can you put the __PRETTY_FUNCTION__ values into PROGMEM so that I don't have to waste real memory unnecessarily?" Is it even possible?
Regards,
Jeff.
Edit/ Sorry, realised that I had inserted a superfluous asterix, *, into the definition of func above which made the actual definition wrong no matter how you looked at it. I have to put that down to frustration with the problem and having been round and round trying various things before realising that I wasn't wrong in what I was writing, but wrong in my assumption about the nature of __PRETTY_FUNCTION__. Apologies.