Repository navigation
Add Integer Literals chapter - #208
Conversation
Adds a new chapter to describe the integer literal behavior as conforming to C. This documents the feature as proposed in: https://github.com/microsoft/hlsl-specs/blob/main/proposals/0017-conforming-literals.md
|
im coming a bit late to this, is there a reason why we don't document short\int16_t or ushort\uint16_t here? |
There is no literal suffix for integers smaller than |
Is there a precedent for a literal suffix for these types? Can we adopt something? Otherwise, when adapting code to comply with the conforming literals language changes in HLSL 202x, code like |
There is no precedent in C. This is probably because C basically implicitly converts all integer types smaller than
We could come up with something ourselves, but I actually think it is better to not create something non-conformant here. Maybe it makes sense to allow literals to start as 16-bit types, and scale up because implicit promotions are cheap. I’m unconvinced we have a good enough reason to deviate from C/C++ here. |
An implementation of https://en.cppreference.com/w/cpp/language/user_literal would make people's lives somewhat bearable. I could make my own
What was the issue with allowing the |
Feel free to file a separate feature request, however due to how DXC implements overload resolution I'm not confident these can be implemented in DXC, so it may need to be a 202y feature instead of 202x.
What is the expected behavior of I don't really understand your concern here. In #304, you're saying we didn't align our We consciously decided to deviate from C/C++ in the floating point behavior due to the computational cost of We choose to align with C/C++ for integers because it is what programmers expect, and the compiler is very capable of providing implicit cast warnings to help find odd cases. I don't know that we're going to make you happy since the feedback you're giving us is self-inconsistent. It seems like you want us to align the language with how you want it to work rather than aligning based on C/C++ or existing usage. |
|
so why doesn't a C++ compiler give me a lot of warnings about uint32_t being casted to uint16_t when DXC does?
You're right. Sorry my bad. |
C/C++ has the most hated conversion feature ever usual arithmetic conversions. Basically all integer values smaller than Because this means a whole lot of extra conversions for shorts, most C/C++ compilers don't warn on conversions that are caused by the usual arithmetic conversions. HLSL does not have usual arithmetic conversions because that would be awful for performance on SIMD processors. |
Adds a new chapter to describe the integer literal behavior as conforming to C. This documents the feature as proposed in: https://github.com/microsoft/hlsl-specs/blob/main/proposals/0017-conforming-literals.md


Adds a new chapter to describe the integer literal behavior as conforming to C. This documents the feature as proposed in:
https://github.com/microsoft/hlsl-specs/blob/main/proposals/0017-conforming-literals.md