Thursday, 15 January 2015

c99 - What is the standard way to log a program in C? -


There is a program in C - which is the --verbose or --debug option, how does this really apply? Without using third party libraries

My goal is not to do this at all times:

  if (debug) printf ("debug msg \ n"); Printf ("Info msg \ n");  

You can specify the following program where a macro is defined and options Has been passed on to the Executive Logging enabled.

  #include & lt; Stdio.h & gt; #include & lt; String.h & gt; # Defined STREQ (a, b)! (Strcmp ((a,, b)) #define logmsg (fmt, ...) \ do {\ if (debug) \ printf (fmt, ## __VA_ARGS __); \} While (0) four debugs; {If (argc> 1) {if (STREQ (argv [1], "debug") debug = 1;} logs ("% s \ n", "int argc, char * argv []" Hello_World "); Return 0;}  

To debug the logic debug as the first argument

Note : This program has been tested on Linux at with the GCC compiler


No comments:

Post a Comment