Freetype 2,建筑 visual studio 2015

Freetype 2, building visual studio 2015

收到以下警告:

ttgload.c(1654): warning C4312: 'type cast': conversion from 'FT_UInt' to 'void *' of greater size

这看起来很奇怪。

有问题的代码行是这样的:

if ( FT_List_Find( &loader->composites,
                   (void*)(unsigned long)glyph_index ) )

glyph_index 声明为 FT_UInt

FT_UInttypedef unsigned int 因此将 int 转换为 void*.

是相当奇怪的

关于如何处理这个警告有什么想法吗?

FT_UInt is typedef unsigned int so it is rather strange to convert an int to a void*.

其实不是。它非常好,可以在整数和指针之间进行转换。它的一个特定应用是 "user parameters" 到一个函数,在该函数中您将整数或指针与函数回调一起注册。

然而,双重类型转换 (void*)(unsigned long) 会导致出现问题。不能保证 sizeof(unsigned ling) >= sizeof(void*) 可能会导致指针的各种问题(即未定义的行为)得到 t运行。

当有人想要一个也可以包含指针的整数时,使用的正确类型是 uintptr_tintptr_t

Any ideas on how to deal with this warning?

在这种特殊情况下,它可能不是问题的原因,因为该指针将被强制转换回 FT_UInt。在长 运行 中,提交问题并更改 FT_List_Find 的原型以接受 uintptr_t 而不是指针是有意义的;不幸的是,这也会破坏很多现有程序。