meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
programming:c:preprocessor:macros [2025/11/01 14:46] – removed - external edit (Unknown date) 127.0.0.1programming:c:preprocessor:macros [2025/11/01 14:50] (current) niziak
Line 1: Line 1:
 +====== macros ======
 +
 +  * [[https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,-tips,-and-idioms|C Preprocessor tricks, tips, and idioms]]
 +  * [[http://jhnet.co.uk/articles/cpp_magic]]
 +  * [[https://medium.com/codex/c-macros-pseudo-generic-methods-and-structs-b4236e6e50b8|C Macros: Pseudo-generic methods and structs]]
 +
 +<code c>
 +#define MAX(a, b) \
 +  ({ __typeof__(a) _a = (a); \
 +      __typeof__(b) _b = (b); \
 +    _a > _b ? _a : _b; })
 +</code>
 +
 +===== bitfields =====
 +
 +<code c>
 +#define BITMASK(bit_len, bit_shift) (((1U << (bit_len))-1) << (bit_shift))
 +</code<
 +
 +  * [[https://stackoverflow.com/questions/31253045/c-macro-to-create-bitfield-defines|C Macro to Create Bitfield Defines]]
 +  * [[https://forum.arduino.cc/t/calculating-bitmask-values/410649/23?page=2|Calculating Bitmask Values]]
 +
 +