把代码发上来啊
# include "My_Assert.h" int main() { ASSERT(1 == 0 , "Error") ; return 0 ; }这是assertion.h文件:
#ifndef ASSERTION #define ASSERTION #ifdef __cplusplus extern "C" { #endif void ASSERT(int exp , char *message); #ifdef __cplusplus } #endif #endif这是My_Assert.h文件:
# include "assertion.h" # include <stdio.h> #ifdef __cplusplus extern "C" { #endif void ASSERT(int exp , char *message) { if(!(exp)) printf("Assertion failed:\t%s\n%s:\t%d\t%s\n" ,#exp , message , __LINE__, __FILE__); } #ifdef __cplusplus } #endif老是在有下划线的地方指示有错误:
#ifndef MY_ASSERT_H #define MY_ASSERT_H #include "assertion.h" #ifdef __cplusplus extern "C" { #endif #include <stdio.h> void ASSERT(int exp , char *message) { if(!(exp)) printf("Assertion failed:%d\t%s\n",exp,message); //printf("Assertion failed:\t%s\n%s:\t%d\t%s\n" ,#exp , message , __LINE__, __FILE__); 参数都没给值么!肯定会出错啊,你想弄啥啊! } #ifdef __cplusplus } #endif #endif