Print variables with file and line number for debugging source code

This snippet submitted by mike lear on 2010-09-08. It has been viewed 10440 times.
Rating of 4.1 with 81 votes

#ifndef __TEMP__H__
#define __TEMP__H__
//
//		Author: Mike Lear [email protected]
//
//		TEMP.H:   Display messages - variables whilst testing source code
//
//		NOTE: 
//		This header uses macros which should not be left in the finished program.
//		Renove this header and any macros used once testing is completed.
//
//		Usage:    
//		Place this header file in your include path, then include the temp header in
//		your source code:
//		IE: 
//			#include <iostream>
//			#include <string>
//			#include <temp.h>
//
//		You can then place SV(var); or DV(var,var); anywhere in your code to display
//		variables,messages etc  during testing.
//
//		SV(var); 			-- Displays the file then line number and a Single Variable
//		DV(var,var);  		-- Displays the file then line number and two (Dual Variables)
//
//      Example Output 
//		vmake.cc:  line no: 225:   count = 0
//      vmake.cc:  line no: 230:   FunKey.test(F7) = 0,  FunKey.test(F8) = 1
//      vmake.cc:  line no: 231:   count = 1



#define SV(m) 	std::cerr <<  __FILE__ << ":  line no: " << __LINE__  << ":   " << #m " = " << m << std::endl;
#define DV(m,l) std::cerr <<  __FILE__ << ":  line no: " << __LINE__  << ":   " << #m " = " << m << ",  " << #l " = " << l << std::endl;


#endif
  
 




More C and C++ source code snippets