Skip to content

Instantly share code, notes, and snippets.

@Esonhugh
Created December 10, 2022 11:12
Show Gist options
  • Save Esonhugh/62a68fc1ec2f93f0494e111ae0c13c7b to your computer and use it in GitHub Desktop.
Save Esonhugh/62a68fc1ec2f93f0494e111ae0c13c7b to your computer and use it in GitHub Desktop.
条件编译Debug模式小工具
/*
C header file for debugging print
DEBUG_HEADER can be modified
and also the if you need debugging in kernel
you may need define PRINT as printk or other print funcs.
Usage:
Compile with gcc and options like `-D DEBUG_MODE` will enable the debug print
if no `-D DEBUG_MODE` will not make the debug function work bug defined.
@author: Esonhugh
*/
// #define DEBUG_MODE
#ifndef DEBUG_HEADER_FILE_INCLOUDED
#define DEBUG_HEADER_FILE_INCLOUDED
#define DEBUG_HEADER "[DEBUG] "
#define PRINT printf
#ifdef DEBUG_MODE
#define DEBUG(str) PRINT(DEBUG_HEADER "%s\n", str)
#define DEBUG_VAR_STRING(name, value) PRINT(DEBUG_HEADER "%s: %s\n", name, value)
#define DEBUG_VAR_INT(name, value) PRINT(DEBUG_HEADER "%s: %d\n", name, value)
#define DEBUG_VAR_LONG(name, value) PRINT(DEBUG_HEADER "%s: %ld\n", name, value)
#define DEBUG_VAR_DOUBLE(name, value) PRINT(DEBUG_HEADER "%s: %lf\n", name, value)
#else
#define DEBUG(str)
#define DEBUG_VAR_STRING(name, value)
#define DEBUG_VAR_INT(name, value)
#define DEBUG_VAR_LONG(name, value)
#define DEBUG_VAR_DOUBLE(name, value)
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment