Get the latest tech news
Detecting if an expression is constant in C
Here's a fun little language puzzle: implement a macro that takes an (integer or floating) expression as an argument and: There's a number of ways to solve this, depending on which C standard you're using and whether compiler extensions are allowed or not. Here are a few I've come across along with some pros and cons.
May change the type of the expression due to the addition, which is subject to the typical integer promotion rules. Here's a neat (or cursed) little solution I came up with: declare the enum inside a function parameter to give it "scope": UPDATE: Multiple readers have pointed out that casting the result of sizeof to void silences the unused warnings (duh!
Or read this on Hacker News