I have forgotten a little, but I am finding that I am remembering more as I write and test my code.
CPP
The C Pre-Processor is so nice.
This has to be one of the nicest asserts that I have ever used:
ASSERT( 1==0 ); ASSERT: "1==0" failed in pc-clisp.c line 672. This turns abc into "abc" - nice. You can use #x in your macro, but the wiki page used QUOTE so I have taken their advice.
#define QUOTE(x) #x#define _TEST( type , test , action ) {\  if( !(test) ){ \
    fprintf( stderr ,\
      QUOTE(type) ": %s failed in %s line %d.\n" , "\"" QUOTE(test) "\"" ,\
      __FILE__ ,\
      __LINE__ );\
    action;\
    }\
  }#define ASSERT( test ) _TEST( ASSERT , test , exit(1) )TEST just runs the test and prints any failed message.
CHECK, instead, returns false on a failure.
For more information, see the wiki entry.#define CHECK( test ) _TEST( CHECK , test , return (1==0) )#define TEST( test ) _TEST( TEST , test , )
 
 
No comments:
Post a Comment
Please use family friendly language.