Close

eye2See - Preprocessor Magic

A project log for eye2see - Tiny Symbolic Debugger for all Arduinos*

* "Tiny Symbolic Debugger for all Arduinos" applies if your project uses an I2C bus or has an available I2C port

mark-hendersonMark Henderson 08/07/2023 at 18:220 Comments

eye2see - C/C++ Preprocessor Magic

The C/C++ preprocessor is a very powerful tool, and a couple of its features are used by eye2see to perform "magic" - namely obtaining key debugging information at run-time: file name, line number, variable size, value and memory location.

These are preprocessor features used (the last 2 are actually native C/C++ features):

__FILE__         //makes file name available to C/C++ macros 
__LINE__         //makes file line number available
#varName         //makes variable name available as a string
sizeof(varName)  //makes byte size of variable available
&varName         //makes memory location of variable available

 By coding the eye2see user functions as macros, and using these features, we can access runtime values and pass them over I2C to the eye2see Probe and then on to the PC GUI via USB for display.

#define e2clog(v,b) E2Clog(__NAME__,#v,b,sizeof(v),v,&v, __LINE__)

Another eye2see macro called __NAME__ takes the file name returned by __FILE__ and strips off the PATH to reduce the display line length.

Discussions