1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <iostream> #include <string.h>
using namespace std;
typedef unsigned char byte; typedef unsigned short word;
#define B_PTR(var) (byte*)((void *)(&var)) #define W_PTR(var) (word*)((void *)(&var))
#define MEN_B(arr) *((byte*)arr) #define MEN_W(arr) *((word*)arr)
#define WORD_LO(xxx) ((byte) ((word)(xxx) & 255)) #define WORD_HI(xxx) ((byte) ((word)(xxx) >> 8))
#define STRUCT_MEN_POS(type,member) (unsigned int)&((type *)0)->member
#define STRUCT_MEN_SIZE(type,member) sizeof( ((type*)0)->member )
#define ARR_SIZE(arr) sizeof(arr)/sizeof(arr[0])
#define STR(s) #s #define STR2(a,b) a##b
struct student { char name[10]; int age; int id; } my_student;
int main(void) { int a = 23;
cout << W_PTR(a) <<endl; cout << MEN_W(W_PTR(a)) <<endl;
cout << STRUCT_MEN_POS(struct student,age) << endl; cout << STRUCT_MEN_SIZE(struct student,name) << endl;
cout << STR(abc) << endl; cout << STR2(2,34) << endl; }
|