Calling a function of a TRACE system in C ++

How to call TRACE in C ++? for example using this simple code

int x = 1;
int y = 16;
float z = 32.0;
TRACE( "This is a TRACE statement\n" );

TRACE( "The value of x is %d\n", x );

TRACE( "x = %d and y = %d\n", x, y );

TRACE( "x = %d and y = %x and z = %f\n", x, y, z );
+3
source share
1 answer

If you mean "How can I track the execution path of my code?" Then you need to use the source level symbolic debugger.

On Linux, this usually means using GDB, for which there are a number of GUI interfaces; using GDB on the command line is cryptic and time-consuming, it can be used, for example, through Eclipse or KDevelop or the standalone Insight debugger. On Windows, the debugger will be specific to the compiler, but VC ++ has the best debugger available (and free in Express Edition).

In response to davit edit

Define the TRACE macro as follows:

#if defined NDEBUG
    #define TRACE( format, ... )
#else
    #define TRACE( format, ... )   printf( "%s::%s(%d)" format, __FILE__, __FUNCTION__,  __LINE__, __VA_ARGS__ )
#endif

, "%s::%s(%d)" format . . , .

+5

Source: https://habr.com/ru/post/1757484/


All Articles