On 2/4/21 1:17 PM, David Brown wrote:
You might find it neater to have:
#ifdef DEBUG
#define DEBUGABLE volatile
#else
#define DEBUGABLE
#endif
Then when you make the variable, you only need:
DEBUGABLE unsigned some_variable;
Thanks for the suggestion, but in truth I was just trying to illustrate
the point. My personal usage is to temporarily add:
volatile // DEBUG
on the line before the declaration, and remove it after debugging the
code in question. See below.
No, it is not an error - it is perfectly fine. The parameter is passed
by value - the "volatile unsigned" is read and passed to the function.
It is only if the function has a pointer that you have an error :
void some_function(unsigned * p);
Calling "some_function(&some_variable)" will fail if some_variable is
declared "volatile".
You are of course right. My apologies for typing too fast and misstating
a problem I've hit many times (passing a volatile by pointer or
reference when a non-volatile is expected).
Here is a trick you might like to try.
...
#define establish(v) asm volatile ("" : "+g" (v))
...
An alternative formulation for the macro would be:
#define establish(v) asm volatile ("" :: "g" (v))
...
Very nice trick(s), thanks. I'll definitely try them. The first declares
a read/write output operand and the second an input, right?
I wonder if anyone has any thoughts about specific -fno-* settings I
can add alongside -Og which will preserve either all, or most, or even
just more, of the local variables rather than optimizing them away.
I still would like to see something like this, as per the original
poster's request. As I said above, I don't leave any of the #if/#define
constructs in release code (nullified by #undef, #define <empty>, etc.)
-- just dynamically add and remove them as needed. Leaving them in
obscures the code too much. A magic "-no-..." option that could be
added/enabled to the commandline or Makefile would make life easier.