實現代碼執行個體
程式碼:
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> /***** cplusplus *****/ #if 0 #include <iostream> using namespace std; #endif // 得到指定地址上的一個位元組或字 #define MEM_B(x) (*((byte *)(x))) #define MEM_W(x) (*((word *)(x))) // 得到一個field在結構體(struct)中的位移量 #define FPOS(type, field) ((dword)&((type *)0)->field) // 將一個字母字元轉換為大寫 #define UPCASE(c) (((c)>='a' && (c)<='z') ? ((c)-0x20) : (c)) // 判斷字元是否為十進位的數字 #define DECCHECK(c) ((c)>='0' && (c)<='9') // 判斷字元是否為十六進位的數字 #define HEXCHECK(hex) (((hex)>='0' && (hex)<='9')||((hex)>='A' && (hex)<='F')||((hex)>='a' && (hex)<='f')) // 防止溢出的一個方法#define INC_SAT(val) (val=((val)+1 > (val)) ? (val)+1 : (val)) // 計算數組元素的個數 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0])) int main(void) { int x = 0x1234abcd; char c = 'a'; char dec = '5'; char hex = 'e'; char array[10] = {'1'}; //printf("MEM_B(x): 0x%p/n", MEM_B(x)); //printf("MEM_W(x): 0x%p/n", MEM_W(x)); printf("UPCASE(c): %c -> %c/n", c, UPCASE(c)); printf("DECCHECK(dec): %c -> %d/n", dec, DECCHECK(dec)); printf("HEXCHECK(hex): %c -> %d/n", hex, HEXCHECK(hex)); printf("ARRAY_SIZE(array): array[10] -> %d/n", ARRAY_SIZE(array)); printf("/n/****** MACRO ******//n"); printf("__LINE__: %d/n", __LINE__); printf("__FILE__: %s/n", __FILE__); printf("__DATE__: %s/n", __DATE__); printf("__TIME__: %s/n", __TIME__); printf("__func__: %s/n", __func__); #ifdef __cplusplus cout <<"hello __cplusplus"<<endl; #endif #ifdef __STDC__ printf("hello __STDC__/n"); #endif printf("/n/****** sizeof() ******//n"); //printf("sizeof(byte): %d/n", sizeof(byte)); printf("sizeof(char): %d/n", sizeof(char)); printf("sizeof(signed char): %d/n", sizeof(signed char)); printf("sizeof(unsigned char): %d/n", sizeof(unsigned char)); printf("sizeof(short): %d/n", sizeof(short)); printf("sizeof(signed short): %d/n", sizeof(signed short)); printf("sizeof(unsigned short): %d/n", sizeof(unsigned short)); printf("sizeof(int): %d/n", sizeof(int)); printf("sizeof(signed int): %d/n", sizeof(signed int)); printf("sizeof(unsigned int): %d/n", sizeof(unsigned int)); printf("sizeof(long): %d/n", sizeof(long)); printf("sizeof(signed long): %d/n", sizeof(signed long)); printf("sizeof(unsigned long): %d/n", sizeof(unsigned long)); printf("sizeof(long long): %d/n", sizeof(long long)); printf("sizeof(signed long long): %d/n", sizeof(signed long long)); printf("sizeof(unsigned long long): %d/n", sizeof(unsigned long long)); printf("sizeof(float): %d/n", sizeof(float)); printf("sizeof(double): %d/n", sizeof(double)); exit(EXIT_SUCCESS); }