Closed nmatthews-witekio closed 9 months ago
Clarification:
Think of a debug routine like printf...
one_bracket_debug("This is the value %d", x); then the one_bracket_debug macro has 2 arguments -- "This is the value %d" and x This means you have to use __va_args__ to deal with the extra multiple optional arguments.
if you use the double-bracket technique then: two_bracket_debug(("This is the value %d", x)); then the two_bracket_debug macro has 1 argument -- ("This is the value %d", x) So it can work without needing __va_args__i.e. on an older compiler.
Also if you do:
the compiler knows that the argument x is unused -- so it can throw away all of -- ("This is the value %d", x) so the string literal "This is the value %d" probably doesn't make it into the executable
You could use __va_args__:
but there's probably a bit less chance for the compiler to be able to discard the string "This is the value %d"
That's all. It looks a bit weird in the code -- but actually it sort of makes sense -- especially if you do
then the single argument -- ("This is the value %d", x) -- gets rewritten easily as printf ("This is the value %d", x)
If you use a #define that just discards its argument -- then the pre-processor stage will just remove the argument -- so the compilation stage won't even "see" the argument -- as it'll have already been removed.
This still needs reviewing @PatriciaFieldhouse.
Not sure what happened -- have adjusted an opened https://github.com/avnet-iotconnect/iotc-generic-c-sdk/pull/46
Add debugging routines
Macro definition with (()) allows all debugging strings to be removed from the executable if required -- keeping executable size smaller -- but allowing debugging to be turned on if/when required.