实现代码实例
程序代码:
#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); }
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索printf
, include
, array
, char
, hex
, define
c++printf
c语言带参数的宏定义、c语言的宏定义、c语言中的宏定义、c的宏定义、c 中的宏定义,以便于您获取更多的相关知识。
时间: 2024-08-03 10:10:35