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 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. (Note: the immediate int cast makes floating constant e.g 1.1 work, but not things like 1.1 + 2.2, without emitting warnings that is). Here's a neat (or cursed) little solution I came up with: declare the enum inside a function parameter to give it "scope":
Or read this on Hacker News