python-cffi / cffi

A Foreign Function Interface package for calling C libraries from Python.
https://cffi.readthedocs.io/en/latest/
Other
114 stars 41 forks source link

Cast offset to size_t to avoid c++11-narrowing warning #92

Closed triallax closed 3 months ago

triallax commented 3 months ago

e.g. with clang 18 on chimera linux:

_CFFI_test_verify_anonymous_struct_with_star_typedef.cpp:583:10: error: non-constant-expression cannot be narrowed from type 'long' to 'size_t' (aka 'unsigned long') in initializer list [-Wc++11-narrowing] 583 | { "a", ((char )&((foo_t)4096)->a) - (char )4096, | ^~~~~~~~~~ _CFFI_test_verify_anonymous_struct_with_star_typedef.cpp:583:10: note: insert an explicit cast to silence this issue 583 | { "a", ((char )&((foo_t)4096)->a) - (char )4096, | ^~~~~~~~~~ | static_cast( )

arigo commented 3 months ago

Thanks. The additional cast looks harmless and if it helps some compilers, then let's go for it.