Why is char** (or any T**) to void** cast invalid?

前端 未结 3 1355
小蘑菇
小蘑菇 2021-01-19 16:21

In the first comment to Python C Module - Malloc fails in specific version of Python, @user694733 mentions that casting char** to void** is not val

3条回答
  •  执念已碎
    2021-01-19 16:55

    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.

提交回复
热议问题