C language inside can define the static assertion, more convenient debugging code.
Using static assertions
1#include <stdio.h>2#include <stdlib.h>3#include <assert.h>4 5 voidMain ()6 {7 intnum = -;8ASSERT (Num < -);//num<20 is normal, otherwise abnormal9printf"%d", num);Ten}
Using your own defined static assertions to implement the
1#include <stdio.h>2#include <stdlib.h>3#include <assert.h>4 5 //define line can not be used to write6 //pre-compilation processing7 8 #defineDEBUG9#ifndef DEBUG//If you do not define a constant debugTen #defineMyassert (x)//definition only, does not write code detection hints One #else A //define Myassert and write code detection hints - #defineMyassert (x) - if(!(x)) the { -printf"Myassert (%s) macro started detection .... \ n", #x); -printf"It's a mistake."); -printf"The current function name is%s, the file name is%s and the code line number is%d", __function__,__file__,__line__); + } - #endif + A at voidMain () - { - intnum = -; -ASSERT (Num < -);//num<20 is normal, otherwise abnormal -printf"%d", num); -}
C-language static assertion-Define your own static assertions