Question Details

No question body available.

Tags

c integer language-lawyer literals

Answers (1)

June 20, 2026 Score: 4 Rep: 236,743 Quality: Medium Completeness: 80%

You are focusing on the wrong question. Your goal is a 32-bit product. The details of the operands are irrelevant as long as the result is that of a 32-bit product (that is, it is the residue modulo 232 of the mathematical product of the operands). Trying to get a 32-bit operand is something you think would help, but the actual goal is the 32-bit product. (This is an XY problem.)

Before C 2024, it is impossible to guarantee a 32-bit operand because, as you note, int could be wider, and then any narrower operand would be promoted to int. So, even if you had an operand that were initially uint32t, whether by cast or use of UINT32C or any other construction, it would be promoted before its participation in the multiplication. The solution is simply to convert the multiplication result to the desired type: (uint32t) (2654435769u key). The conversion rules are such this will produce the desired residue, regardless of the width of int. In other words, converting to the desired result type, not controlling the operand type, gives the desired behavior.

In C 2024, there is a solution using your X question, but the type of key must also be controlled. In C 2024, the uwb suffix specifies an unsigned bit-precise integer type that is just wide enough, so 2654435769uwb has type unsigned _BitInt(32). Then, if key also has type unsigned _BitInt(32), 2654435769uwb key specifies a 32-bit multiplication—no more and no less. (If key does not have type unsigned BitInt(32) and you do not want to change it, you can cast it in the multiplication: 2654435769uwb * (unsigned BitInt(32)) key.)

(As an example, printf("%d\n", (int) (3uwb * 3uwb)) prints “1”, showing the multiplication is performed using just two bits and not using the int type, which would produce 9.)