为什么CHAR **(或任意t **)作废**投无效? [英] Why is char** (or any T**) to void** cast invalid?

查看:113
本文介绍了为什么CHAR **(或任意t **)作废**投无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在第一个注释来 Python的I2C模块 - malloc的在Python ,@ user694733的特定版本未能提到铸造的char ** 无效** 是无效的。我读<一个href=\"http://stackoverflow.com/questions/27938860/invalid-conversion-from-foo-to-void-why-is-implicit-type-conversion-allowe\">Invalid从富转换**作废** - 这是为什么允许到void *隐式类型转换而不是无效** 并的 http://c-faq.com/ptrs/genericpp.html 但有一个参考标准,但没有实际的例子,在这种情况下,这可能是不正确的,从而导致errores。例如的思考无效** 双** 或者相反,有没有在那里可以出错的情况?为什么(在技术上,不只是因为它是UB)?


解决方案

  

,但有一个参考标准,但没有实际的例子,在这种情况下,这可能是不正确的,从而导致错误的


这是不准确的。其中你提到的网页。 http://c-faq.com/ptrs/genericpp.html 指向其他网页。 http://c-faq.com/null/machexamp.html 它包含与不同的指针的大小为不同类型的机器的例子:


  

从数据一般Eclipse的MV系列有三个其中两个是由C编译器使用的架构支持的指针格式(字,字节和比特指针),:字节指针的char *和void *的,和一切字指针。用于从16位诺瓦线的32位中压线的进化过程中的历史原因,字指针和字节指针已偏移在字不同的地方,间接和环保护比特。传递不匹配的指针格式功能导致保护错误。最终,MV C编译器添加了许多兼容性选项,以试图解决code,它有指针类型不匹配错误。


In the first comment to Python C Module - Malloc fails in specific version of Python, @user694733 mentions that casting char** to void** is not valid. I read Invalid conversion from Foo** to void** - why is implicit type conversion allowed to void* but not to void**? and http://c-faq.com/ptrs/genericpp.html but there is a reference to standard, but no real example, in which case this might be incorrect, leading to errores . Thinking of e.g. void** to double** or vice versa, is there a case where it can go wrong? Why (technically, not just because it is UB)?

解决方案

but there is a reference to standard, but no real example, in which case this might be incorrect, leading to errors

This is not accurate. Page http://c-faq.com/ptrs/genericpp.html which you mentioned points to another page http://c-faq.com/null/machexamp.html which contains an example of machines with different pointer sizes for different types:

The Eclipse MV series from Data General has three architecturally supported pointer formats (word, byte, and bit pointers), two of which are used by C compilers: byte pointers for char * and void *, and word pointers for everything else. For historical reasons during the evolution of the 32-bit MV line from the 16-bit Nova line, word pointers and byte pointers had the offset, indirection, and ring protection bits in different places in the word. Passing a mismatched pointer format to a function resulted in protection faults. Eventually, the MV C compiler added many compatibility options to try to deal with code that had pointer type mismatch errors.

这篇关于为什么CHAR **(或任意t **)作废**投无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆