简体   繁体   English

Freetype 2,Building Visual Studio 2015

[英]Freetype 2, building visual studio 2015

Getting the following warning: 得到以下警告:

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

Which seems rather odd. 这似乎很奇怪。

The line of code in question is this: 有问题的代码行是这样的:

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

and glyph_index is declared FT_UInt . 并且glyph_index被声明为FT_UInt

FT_UInt is typedef unsigned int so it is rather strange to convert an int to a void* . FT_UInttypedef unsigned int因此将int转换为void*是很奇怪的。

Any ideas on how to deal with this warning? 关于如何处理此警告有什么想法?

FT_UInt is typedef unsigned int so it is rather strange to convert an int to a void*. FT_UInt是typedef unsigned int,因此将int转换为void *很奇怪。

Actually it's not. 其实不是。 It's perfectly fine and allowed to convert between integers and pointers. 很好,可以在整数和指针之间进行转换。 A particular application of this is "user parameters" to a function where you register integer or a pointer together with a function callback. 此功能的一个特殊应用是对函数的“用户参数”,您可以在其中注册整数或指针以及函数回调。

However the two-fold typecast (void*)(unsigned long) is a recipe for getting problems. 但是,双重类型转换(void*)(unsigned long)是解决问题的良方。 It's not guaranteed that sizeof(unsigned ling) >= sizeof(void*) which may cause all kinds of problems (ie undefined behaviour) of pointers get truncated. 不能保证sizeof(unsigned ling) >= sizeof(void*)可能会导致指针的各种问题(即未定义的行为)被截断。

The proper types to use when someone wants an integer that also can hold a pointer are uintptr_t and intptr_t . uintptr_tintptr_t是在有人想要一个也可以容纳指针的整数时使用的正确类型。

Any ideas on how to deal with this warning? 关于如何处理此警告有什么想法?

In this particular case it's likely not a cause of problems, because that pointer is going to be cast back to an FT_UInt. 在这种特殊情况下,这可能不是问题的根源,因为该指针将被投射回FT_UInt。 In the long run it would make sense to file an issue and change the prototype of FT_List_Find to accept a uintptr_t instead of a pointer; 从长远来看,提出问题并更改FT_List_Find的原型以接受uintptr_t而不是指针是有意义的。 unfortunately this would also break a lot of existing programs. 不幸的是,这也会破坏许多现有程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM