C常用宏定义 Standard Macros — commonly-used macros

本文介绍了GLib库中的几个实用宏定义,包括检查目录分隔符、计算最小值和最大值、绝对值及限制数值范围的方法。此外,还详细列出了用于不同位数整数的数据类型定义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

摘自:https://developer.gnome.org/glib/stable/glib-Standard-Macros.html

#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')

Checks whether a character is a directory separator. It returns TRUE for '/' on UNIX machines and for '\' or '/' under Windows.

 

#define MIN(a, b)  (((a) < (b)) ? (a) : (b))

Calculates the minimum of a and b .

 

#define MAX(a, b)  (((a) > (b)) ? (a) : (b))

Calculates the maximum of a and b .

 

#define ABS(a)	   (((a) < 0) ? -(a) : (a))

Calculates the absolute value of a . The absolute value is simply the number with any negative sign taken away.

#define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))

Ensures that x is between the limits set by low and high . If low is greater than high the result is undefined.

 

数据类型定义:[来自https://www.microchip.com/webdoc/AVRLibcReferenceManual/group__avr__stdint.html]

typedef signed char int8_t 
typedef unsigned char uint8_t 
typedef signed int int16_t 
typedef unsigned int uint16_t 
typedef signed long int int32_t 
typedef unsigned long int uint32_t 
typedef signed long long int int64_t 
typedef unsigned long long int uint64_t 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值