Detecting Constant Expressions in C: A Macro-Based Approach

2025-05-13

This article explores various methods for creating a C macro that checks if an expression is a compile-time constant. The author investigates approaches using C23's `constexpr` and `typeof`, GNU extensions like `__builtin_constant_p`, C11's `static_assert`, and clever tricks with `sizeof` and compound literals. Each method has its strengths and weaknesses; some require newer C standards, rely on compiler extensions, or might alter the expression's type or generate warnings. The article concludes by summarizing the pros and cons and expressing a desire for more elegant solutions.

Read more
Development compile-time constant

Checking for Constant Expressions in C: A Macro Approach

2025-04-22

This article explores various methods for creating a C macro that detects if an expression is a constant expression. The author investigates several techniques, including C23's static compound literals, GNU extension `__builtin_constant_p`, `static_assert`, `sizeof` combined with compound literal arrays, `sizeof` with enum constants, and the comma operator. Each method has its pros and cons; C23 support is limited, `__builtin_constant_p` relies on GNU extensions, `static_assert` and `sizeof` methods might alter the expression's type, and the comma operator generates warnings. The author concludes that a perfect solution is elusive, and the best choice depends on specific needs and the C standard version.

Read more

Conquering Advent of Code 2024 with BQN

2025-01-25

The author participated in the 2024 Advent of Code challenge and chose to learn the array language BQN. The article details the learning journey, covering setup, documentation and tooling experiences, and an introduction to BQN's features such as its unique operators, array manipulations, and function definitions. Several Advent of Code solutions are shared, showcasing BQN's strengths in handling arrays and grid problems, contrasting BQN with imperative languages. While initially challenging, the author ultimately finds BQN a fun and powerful language, particularly suited for solving programming puzzles.

Read more
Development array language