ensure codes conforms ISO c11 standard.

This commit is contained in:
Gatsby Van
2023-12-21 14:56:35 +08:00
parent ebe3ebf71d
commit 955478d01d
2 changed files with 48 additions and 52 deletions
+42 -47
View File
@@ -1,28 +1,13 @@
/*****************************************************************************/ /*****************************************************************************/
/**
* Description: A brief description of this file
*
* Author: Fan Hao
* Date: 2022-10-21 18:59
* LastEditors: Fan Hao
* LastEditTime: 2023-02-13 10:01
* Revisions: Rev x.x
* History:
* [YYYY-MM-DD]: Description of modification.
*
* Copyright(c) 2023 Beijing Institute of Technology.
* Lab of Communication and Networking
*
******************************************************************************/
/*****************************************************************************/
/** /**
* Description: Common definitions * Description: Common definitions
* *
* Date: 2021-12-04 16:32 * Date: 2023-12-21 16:32
* LastEditors: Fan Hao * LastEditors: Fan Hao
* LastEditTime: 2022-07-16 17:13 * LastEditTime: 2022-07-16 17:13
* Revisions: Rev 0.1 * Revisions: Rev 0.1
* History: * History:
* [2023-12-21]: Ensure the code conform ISO C11 standard.
* [2022-07-16]: New branch for Dijian. * [2022-07-16]: New branch for Dijian.
* [2021-11-16]: Initial version. * [2021-11-16]: Initial version.
* *
@@ -40,49 +25,59 @@
#include "util.h" #include "util.h"
#include "error.h" #include "error.h"
#include "../config/app_config.h" #include "../config/app_config.h"
/************************** Constant Definitions *****************************/ /************************** Constant Definitions *****************************/
/***************** Macros (Inline Functions) Definitions *********************/ /***************** Macros (Inline Functions) Definitions *********************/
//#define ASSERT(exp) assert(exp) #define __PRINT_BLOCK(block) do {\
#define ASSERT(exp) ((exp) ? 0 : AppAssert(__FILE__, __LINE__)) block\
#define _nop_() asm("nop") } while(0)
#define HALT_IF_ERR(status, msg, ...) \ #define ASSERT(exp) ((exp) ? (void)0 : AppAssert(__FILE__, __LINE__))
if (SUCCESS != status) { \ #define _nop_() __asm__("nop")
printf("ERROR: #%d " msg, status, ##__VA_ARGS__); \
exit(status); \
}
/* Stringify */ /* Stringify */
#define STR(x) #x #define STR(x) #x
// #define _DEBUG_LEVEL 3 #define _814_DEBUG_LEVEL 3
#if _DEBUG_LEVEL == 1 #if _814_DEBUG_LEVEL > 0
#define DBG_ERROR(MSG, ...) printf("in"__FILE__" #%4d [error] "MSG,__LINE__, ##__VA_ARGS__) #define DBG_PRINT(...) printf(__VA_ARGS__)
#define DBG_WARNING(MSG, ...) {} #endif
#define DBG_INFO(MSG, ...) {} #if _814_DEBUG_LEVEL >= 1
#define DBG_PRINT(MSG, ...) printf(MSG, ##__VA_ARGS__) #define DBG_ERROR(...) __PRINT_BLOCK( \
#elif _DEBUG_LEVEL == 2 printf("in"__FILE__" #%4d [error]\t",__LINE__); \
#define DBG_ERROR(MSG, ...) printf("in"__FILE__" #%4d [error] "MSG,__LINE__, ##__VA_ARGS__) printf(__VA_ARGS__); \
#define DBG_WARNING(MSG, ...) printf("[warning] "MSG, ##__VA_ARGS__) )
#define DBG_INFO(MSG, ...) {} #endif
#define DBG_PRINT(MSG, ...) printf(MSG, ##__VA_ARGS__) #if _814_DEBUG_LEVEL >= 2
#elif _DEBUG_LEVEL == 3 #define DBG_WARNING(...) __PRINT_BLOCK( \
#define DBG_ERROR(MSG, ...) printf("in"__FILE__" #%4d [error] "MSG,__LINE__, ##__VA_ARGS__) printf("[warning]\t"); \
#define DBG_WARNING(MSG, ...) printf("[warning] "MSG, ##__VA_ARGS__) printf(__VA_ARGS__); \
#define DBG_INFO(MSG, ...) printf("[Info] "MSG, ##__VA_ARGS__) )
#define DBG_PRINT(MSG, ...) printf(MSG, ##__VA_ARGS__) #endif
#else #if _814_DEBUG_LEVEL >= 3
#define DBG_ERROR(MSG, ...) {} #define DBG_INFO(...) __PRINT_BLOCK( \
#define DBG_WARNING(MSG, ...) {} printf("[Info]\t"); \
#define DBG_INFO(MSG, ...) {} printf(__VA_ARGS__); \
#define DBG_PRINT(MSG, ...) {} )
#endif #endif
#ifndef DBG_ERROR
#define DBG_ERROR(...) {}
#endif
#ifndef DBG_WARNING
#define DBG_WARNING(...) {}
#endif
#ifndef DBG_INFO
#define DBG_INFO(...) {}
#endif
#ifndef DBG_PRINT
#define DBG_PRINT(...) {}
#endif
/**************************** Type Definitions *******************************/ /**************************** Type Definitions *******************************/
/************************** Variable Definitions *****************************/ /************************** Variable Definitions *****************************/
/************************** Function Prototypes ******************************/ /************************** Function Prototypes ******************************/
void AppAssert(const char * file, int line); void AppAssert(const char * file, int line);
#endif /* COMMON_H_ */ #endif /* __COMMON_H_ */
+6 -5
View File
@@ -30,14 +30,15 @@
/*****************************************************************************/ /*****************************************************************************/
/** /**
* @brief * @brief Throw an assert.
* *
* @param * @param file indicate the filename of the assertion
* @param line indicate which line the assertion occurs
* *
* @return * @return NONE.
* *
******************************************************************************/ ******************************************************************************/
void AppAssert(const char * file, int line){ void AppAssert(const char * file, int line){
DBG_ERROR("Assert: %s, #%d.\n", file, line); DBG_PRINT("in %s #%4d [assert] ",file, line);
while(1); while(1);
}; }