一次疏忽导致的bug

NBB_PUT_SHORT 这个宏是按char* 类型算指针的
实际工作中,没有注意这一点,输入指针类型 强转为了 SHORT*
导致 填充的内容错误 这是第一次在工作中遇到 指针类型相关的问题
值得记录一笔
 // ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h> typedef unsigned char NBB_BYTE; /* 8 bits */
typedef signed char NBB_CHAR; /* */
typedef signed short NBB_SHORT; /* 2 byte signed integer */
typedef unsigned short NBB_USHORT; /* 2 byte unsigned integer */
typedef signed long NBB_LONG; /* 4 byte signed integer */
typedef unsigned long NBB_ULONG; /* 4 byte unsigned integer */
typedef signed int NBB_INT; /* >= 2 byte signed integer (machine */
/* word) */
typedef unsigned int NBB_UINT; /* >= 2 byte unsigned integer */
/* machine word) */
typedef int NBB_BOOL; /* boolean */
typedef void NBB_VOID; /* void if supported, char otherwise */ typedef NBB_BYTE* BFD_PUC_ALARM_INFO; BFD_PUC_ALARM_INFO g_pucAlarmInfo; /* ״̬Éϱ¨Ð­ÒéÕ» */ #define NBB_PUT_SHORT(B, S) \
(B)[] = (unsigned char)((S) >> ); \
(B)[] = (unsigned char)((S) & 0xFF) void init()
{
g_pucAlarmInfo = (BFD_PUC_ALARM_INFO) malloc();
memset(g_pucAlarmInfo, , );
}
int main()
{
NBB_BYTE ucLocalSlot = ;
NBB_BYTE ucMainSlot = ;/* Ö÷ÓÃÖ÷¿ØÅ̵IJÛλºÅ */
NBB_BYTE *pucInfoTmp = NULL;
NBB_USHORT *pusData = NULL;
NBB_ULONG ulDataLenth = ; init(); pucInfoTmp = g_pucAlarmInfo + ;
pusData = (char *)pucInfoTmp;
*pusData = 0x0001;
#if 0
NBB_PUT_SHORT(pusData, 0x0001); /* ÌîдÀàÐÍ */
#else
pusData[] =(unsigned char)( 0x0001 >> );
pusData[] =(unsigned char)( 0x0001 & 0xff); #endif
pucInfoTmp = pucInfoTmp + ;
return ;
}
上一篇:从零开始学spring cloud(五) -------- 将服务注册到Eureka上


下一篇:安装完 MySQL 后必须调整的 10 项配置(转)