[File] [PATCH] Avoid cast of address constant to integer constant in initalizer
christos at zoulas.com
Sat Dec 21 17:53:06 UTC 2019
On Dec 20, 3:49pm, mforney at mforney.org (Michael Forney) wrote:
-- Subject: [File] [PATCH] Avoid cast of address constant to integer constant
| RCAST converts an address constant to an integer, and then to pointer. An
| integer constant cast to a pointer type is a valid address constant,
| however, a pointer cast to a integer is not an integer constant:
| > Cast operators in an integer constant expression shall only convert
| > arithmetic types to integer types, except as part of an operand to the
| > sizeof operator.
| So the result of RCAST(const void *, zlibcmp) is not technically a
| constant expression, and might be rejected by some compilers when it is
| used in an initializer for an object with static storage.
| Instead, just use a union so no casts are necessary.
| Initializing the second member of a union requires C99 initialization
| syntax. I couldn't figure out if file is strictly ANSI C, but if so,
| the union could be replaced with two struct members instead.
Committed, thanks! I kept the C99 init, but did not make it a transparent
union :-). Let's see if anyone complains...
More information about the File