and GCC 4.2 prereleases (this was settled way before 4.3) was following these rules: the cast of a function pointer did not result in NULL, as I wrote, but attempting to call a function through a incompatible type, i.e.func = (cb_t)nothing;func(1);根据您的示例,将导致 abort.他们改回 4.1 的行为(允许但警告),部分原因是此更改破坏了 OpenSSL,但同时 OpenSSL 已得到修复,这是编译器可以随时自由更改的未定义行为.from your example, would result in an abort. They changed back to the 4.1 behavior (allow but warn), partly because this change broke OpenSSL, but OpenSSL has been fixed in the meantime, and this is undefined behavior which the compiler is free to change at any time.OpenSSL 只是将函数指针转换为指向其他函数类型的函数指针,这些函数类型采用和返回相同数量的相同大小的值,并且这(假设您不处理浮点数)在所有平台上都是安全的,并且我知道的调用约定.但是,其他任何东西都可能不安全.OpenSSL was only casting functions pointers to other function types taking and returning the same number of values of the same exact sizes, and this (assuming you're not dealing with floating-point) happens to be safe across all the platforms and calling conventions I know of. However, anything else is potentially unsafe. 这篇关于函数指针转换为不同的签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 12:27