您的位置:首页 > 产品设计 > UI/UE

the macro of watch variable value and its memory content

2015-05-05 23:07 411 查看
//replace the printf() with your log function

#include "stdafx.h"

#include <stddef.h>

typedef int INT;

typedef unsigned char BYTE;

typedef short SHORT;

#define WatchVarVal(fmt, Var)
{
\

printf(#Var##" value: "##fmt##"\n", Var);
\

}

// the local variable _i must be different from the input argument Var in this macro,otherwise error will occur.

#define WatchVarMem(Var)
{ \

int _i; \

printf(#Var##" addr: 0x%x"##", size: %d bytes\n", &Var, sizeof(Var));
\

for(_i = 0; _i < sizeof(Var); _i++)
\

printf("Byte[%d]:0x%x\n", _i, *((unsigned char *)&Var + _i));
\

}

int _tmain(int argc, _TCHAR* argv[])

{

INT iVar = 1023;

double dblVar = 2.34567;

WatchVarVal("%d", iVar);

WatchVarMem(iVar);

WatchVarVal("%f", dblVar);

WatchVarMem(dblVar);

getchar();

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐