반응형
#define READ_U8(_val, _ptr) { \ _val = *((unsigned char *) (_ptr)); \ } #define READ_S8(_val, _ptr) { \ _val = *((char *) (_ptr)); \ } #define READ_U16(_val, _ptr) { \ _val = *((unsigned short *) (_ptr)); \ } #define READ_S16(_val, _ptr) { \ _val = *((short *) (_ptr)); \ } #define READ_U24(_val, _ptr) { \ _val = *((unsigned int *) (_ptr)) >> 8; \ } #define READ_S24(_val, _ptr) { \ _val = *((int *) (_ptr)) >> 8; \ } #define READ_U32(_val, _ptr) { \ _val = *((unsigned int *) (_ptr)); \ } #define READ_S32(_val, _ptr) { \ _val = *((int *) (_ptr)); \ } #define WRITE_U8(_ptr, _val) { \ *((unsigned char *) (_ptr)) = _val; \ } #define WRITE_S8(_ptr, _val) { \ *((char *) (_ptr)) = _val; \ } #define WRITE_U16(_ptr, _val) { \ *((unsigned short *) (_ptr)) = _val; \ } #define WRITE_S16(_ptr, _val) { \ *((short *) (_ptr)) = _val; \ } #define WRITE_U24(_ptr, _val) { \ *((unsigned int *) (_ptr)) = _val; \ *((unsigned int *) (_ptr)) <<= 8; \ } #define WRITE_S24(_ptr, _val) { \ *((int *) (_ptr)) = _val; \ *((int *) (_ptr)) <<= 8; \ } #define WRITE_U32(_ptr, _val) { \ *((unsigned int *) (_ptr)) = _val; \ } #define WRITE_S32(_ptr, _val) { \ *((int *) (_ptr)) = _val; \ }
[EX]
char *input_data = xxx.data;
unsigned short aaa=2;
WRITE_U16(input_data, aaa)
input_data += 2;
....
READ_U16(aaa, input_data);
반응형
'IT Tech > Programming' 카테고리의 다른 글
[C언어] c/c++ gcc 디버깅을 위한 gdb 초간단 사용팁 (0) | 2012.03.10 |
---|---|
[C언어] Fast Integer ID Pool 관리 - 할당/반환 함수 (0) | 2011.12.19 |
[C언어] uint2bin (0) | 2011.09.07 |
[Lex&Yacc] Yacc 명령 그리고 Debugging!! (0) | 2011.04.19 |
[C언어] IP 관련 매크로(Macro) (0) | 2011.04.14 |
[regex] 정규표현식 테스트 프로그램 - The Regex Coach (0) | 2011.04.13 |
[C언어] parse Mac Address (0) | 2011.04.08 |
[C언어] Endian 체크 (0) | 2011.03.28 |
[C언어] structure file dump and reading (0) | 2011.03.26 |
[C언어] HexaDump (0) | 2011.03.25 |