Urgent.News

What's breaking now, across thousands of outlets.

Tech

My C23 Conventions

In the latest installment of my exploration into modern C as of 2026, I've discovered three new conventions that have significantly improved my coding practices. The first of these is centered around the [[nodiscard]] keyword. When rendering app windows or panels, it's crucial that the caller captures the rendered rectangle for subsequent processing.

This simple requirement has made [[nodiscard]] an indispensable tool for catching business logic bugs. However, there are instances where a drawn element has no use for the resulting rect. Previously, I would use an UNUSED() macro to suppress the warning, but now I've replaced it with [[maybe_unused]]. This change has improved my code's readability and eliminated the need for the macro altogether.

Another convention I've embraced is the use of [[maybe_unused]] for marking variables that are intentionally unused. This practice has made my code cleaner and more concise, as I no longer need to maintain a separate macro for marking unused variables. Additionally, I've noticed that many routines return different types marked with [[nodiscard]]. In these cases, it makes sense to forgo a specific macro and simply use [[maybe_unused]]. This approach has streamlined my codebase and reduced the need for custom macros.

One surprising revelation in modern C is the behavior of union members. Previously, I assumed that all union members would be zeroed, but this is not always the case. In C23, only the time_t member is guaranteed to be zeroed. This change has introduced some uncertainty into my code, as I can no longer rely on the {0} initializer to clear all union members.

According to Jens Gustedt, specifying the underlying integer type for enumeration constants is a better practice. This advice has prompted me to be more cautious when defining enums and to avoid potential surprises due to unexpected type sizes.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at abner.page →

More in Tech

Total Reserves Near $27 Billion

Pakistan’s foreign exchange reserves witnessed an increase during the week ended October 9, 2026. According to the State Bank of … Read More The post Total Reserves Near $27 Billion appeared first on…

More from Thursday 15 October →