Summary: | stdint.h misdefines UINT8_C and UINT16_C to append U | ||
---|---|---|---|
Product: | glibc | Reporter: | Paul Eggert <eggert> |
Component: | libc | Assignee: | Ulrich Drepper <drepper.fsp> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | clement.pit, glibc-bugs |
Priority: | P2 | Flags: | fweimer:
security-
|
Version: | 2.4 | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Last reconfirmed: | ||
Attachments: | UINT8_C and UINT16_C should not append U |
Description
Paul Eggert
2006-06-24 06:35:40 UTC
Created attachment 1121 [details]
UINT8_C and UINT16_C should not append U
The specificaiton is broken one way or another so I don't really care. The patch is in cvs. Paul, wouldn't it be better to also include a cast to uint_least8_t in that macro (that's what other libcs do, AFAICT)? Right now UINTC_8(-1) produces an negative int, which is rather surprising. UINTC_8(-1) is undefined. (In reply to Clément from comment #3) > Paul, wouldn't it be better to also include a cast to uint_least8_t in that > macro (that's what other libcs do, AFAICT)? Right now UINTC_8(-1) produces > an negative int, which is rather surprising. I think the cast would be incorrect according to C11 because the “type of the expression shall have the same type as would an expression of the corresponding type converted according to the integer promotions.” I think a definition like #define UINTC_8(c) ((uint_least_8_t) +(c)) wouldn't satisfy the requirement. (The + is needed so that the expression can be used in an #if preprocessor context, as required.) musl and bionic have the same definition as glibc. The FreeBSD definition adds parentheses, but still has no cast. (In reply to Florian Weimer from comment #5) > I think the cast would be incorrect according to C11 because the “type of > the expression shall have the same type as would an expression of the > corresponding type converted according to the integer promotions.” I think > a definition like > > #define UINTC_8(c) ((uint_least_8_t) +(c)) > > wouldn't satisfy the requirement. (The + is needed so that the expression > can be used in an #if preprocessor context, as required.) Interesting, thanks a lot. I had checked AVR-libc and QP/C++, which use ((uint8_t) __CONCAT(value, U)) and (static_cast<std::uint8_t>(x_)) respectively. |