Why does Visual C++ warn on implicit cast from const void ** to void * in C, but not in C++?

后端 未结 2 1339
天涯浪人
天涯浪人 2020-12-06 05:17

Summary

The C/C++ compiler in Microsoft Visual Studio gives warning C4090 when a C program tries to convert a pointer to pointer to const data (like <

2条回答
  •  鱼传尺愫
    2020-12-06 05:35

    Like 6502 says this seems to be a bug in the compiler. However, you also ask what you should do about it.

    My answer is that you should add an explicit cast to the free call, and then a comment explaining why it is needed. Bugs in the compiler do happen, use the easiest workaround and add a note such that it can be tested if the bug has been resolved later.

    Extra points for also reporting the bug to the compiler vendor.

    As for 1. It seems to be referring to implicitly casting a const T * to a void *, which should be a warning in C and an error in C++.

提交回复
热议问题