![]() |
SyterKit 0.4.0.x
SyterKit is a bare-metal framework
|
Standard definitions for C and C++. More...

Go to the source code of this file.
Macros | |
| #define | NULL ((void *) 0) |
| Null pointer constant. | |
| #define | offsetof(type, field) ((size_t) (&((type *) 0)->field)) |
| Get the offset of a member within a structure. | |
| #define | container_of(ptr, type, member) |
| Get a pointer to the container structure from a pointer to a member. | |
| #define | likely(expr) (!!(expr)) |
| Likely expression hint for branch prediction. | |
| #define | unlikely(expr) (!!(expr)) |
| #define | min(a, b) (((a) < (b)) ? (a) : (b)) |
| Minimum of two values. | |
| #define | max(a, b) (((a) > (b)) ? (a) : (b)) |
| Maximum of two values. | |
| #define | clamp(v, a, b) min(max(a, v), b) |
| Clamp a value between a minimum and maximum. | |
| #define | ifloor(x) ((x) > 0 ? (int) (x) : (int) ((x) -0.9999999999)) |
| Integer floor of a floating-point value. | |
| #define | iround(x) ((x) > 0 ? (int) ((x) + 0.5) : (int) ((x) -0.5)) |
| Integer rounding of a floating-point value. | |
| #define | iceil(x) ((x) > 0 ? (int) ((x) + 0.9999999999) : (int) (x)) |
| Integer ceiling of a floating-point value. | |
| #define | idiv255(x) ((((int) (x) + 1) * 257) >> 16) |
| Divide an integer by 255 efficiently. | |
Standard definitions for C and C++.
This file contains several macros and definitions used in both C and C++ code. It defines types, utility macros, and compiler-specific optimizations for portability across different compilers.
Clamp a value between a minimum and maximum.
This macro ensures that the value v is between a and b. If v is smaller than a, it returns a, and if v is greater than b, it returns b.
| v | Value to be clamped. |
| a | Minimum bound. |
| b | Maximum bound. |
| #define container_of | ( | ptr, | |
| type, | |||
| member | |||
| ) |
Get a pointer to the container structure from a pointer to a member.
This macro computes the address of the container structure from a pointer to a member within the structure. This is useful for traversing linked data structures like lists or trees.
| ptr | Pointer to the member. |
| type | Type of the structure containing the member. |
| member | Name of the member in the structure. |
| #define iceil | ( | x | ) | ((x) > 0 ? (int) ((x) + 0.9999999999) : (int) (x)) |
Integer ceiling of a floating-point value.
Computes the ceiling of a floating-point value x, rounding up to the nearest integer.
| x | The floating-point value. |
x. | #define idiv255 | ( | x | ) | ((((int) (x) + 1) * 257) >> 16) |
Divide an integer by 255 efficiently.
Performs division of an integer by 255, with an efficient algorithm using bit shifts. This is useful for applications where division by 255 is common, such as image processing.
| x | The integer value. |
x by 255. | #define ifloor | ( | x | ) | ((x) > 0 ? (int) (x) : (int) ((x) -0.9999999999)) |
Integer floor of a floating-point value.
Computes the integer floor of a floating-point value x. If x is positive, it truncates towards zero; otherwise, it rounds down to the nearest integer.
| x | The floating-point value. |
x. | #define iround | ( | x | ) | ((x) > 0 ? (int) ((x) + 0.5) : (int) ((x) -0.5)) |
Integer rounding of a floating-point value.
Rounds a floating-point value x to the nearest integer. Rounds up if x is positive and 0.5 or more, and rounds down otherwise.
| x | The floating-point value. |
x. | #define likely | ( | expr | ) | (!!(expr)) |
Likely expression hint for branch prediction.
Provides a hint to the compiler that the given expression is likely to be true. This helps the compiler optimize the code, improving performance in certain cases.
| expr | Expression that is likely true. |
| #define max | ( | a, | |
| b | |||
| ) | (((a) > (b)) ? (a) : (b)) |
Maximum of two values.
Returns the larger of two values, a and b.
| a | First value. |
| b | Second value. |
| #define min | ( | a, | |
| b | |||
| ) | (((a) < (b)) ? (a) : (b)) |
Minimum of two values.
Returns the smaller of two values, a and b.
| a | First value. |
| b | Second value. |
| #define NULL ((void *) 0) |
Null pointer constant.
Defines the value of NULL. In C++, NULL is defined as 0, while in C, it is defined as a void pointer of value 0. The NULL macro can be used to represent null pointers in both languages.
| #define offsetof | ( | type, | |
| field | |||
| ) | ((size_t) (&((type *) 0)->field)) |
Get the offset of a member within a structure.
Returns the byte offset of a given member within a structure. This is useful when working with low-level memory manipulation or in custom memory allocation schemes.
| type | The type of the structure. |
| member | The member of the structure whose offset is to be calculated. |
| #define unlikely | ( | expr | ) | (!!(expr)) |