News for hackers. Stuff that matters.
Re:Detecting if an expression is constant in C by rurban on Tuesday April 22, 2025 @02:26PM (#43764904)
The macro should be called IS_CONST(), not C()
Re:Detecting if an expression is constant in C by atiedebee on Tuesday April 22, 2025 @03:25PM (#43765406)
I agree, but for a blog post it is more concise (IS_CONST or anything that is long would take up a lot more screen real estate on my phone).
Re:Detecting if an expression is constant in C by immibis on Tuesday April 22, 2025 @02:41PM (#43765031)
To determine if an expression is constant in C, one must determine if an expression in C is constant.
Re:Detecting if an expression is constant in C by mrgriffin on Wednesday April 23, 2025 @04:06AM (#43769709)
Would you expect IS_CONST to evaluate to the constant? With a name like that I would expect it to evaluate to true/false.

C here is asserting that the value inside is a constant and then evaluating to that constant.

Re:Detecting if an expression is constant in C by rurban on Wednesday April 23, 2025 @04:15AM (#43769748)
Uh, you are right. C is the right name. It throws.

I mixed it up with a similar compile-time constness check in some of my libraries, where I decided if const of not. gcc throws, only clang could give me a proper answer.