C宏定義的小結

來源:互聯網
上載者:User

實現代碼執行個體

程式碼:

#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);     }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.