Disabling “cast from pointer to smaller type uint32_t” error in Clang

后端 未结 5 2265
余生分开走
余生分开走 2021-02-15 12:09

I\'m working on a school project that involves porting a large piece of C++ code on an experimental piece of hardware. Unfortunately, that hardware is 64-bit and the code contai

5条回答
  •  -上瘾入骨i
    2021-02-15 12:42

    I agree that you should bite the bullet and fix the code to use the correct integer type. But to answer your question: No, you can't disable it, though you can work around it.

    Many errors come from warnings. A good thing in general, but if you want to disable the warning, just do it. Since the culprit is probably something like -Wall which enables many warnings you should keep on, you should selectively disable this single warning. The error message mentions the diagnostic responsible for error message, e.g. ... [-Wextra-tokens] (if it doesn't, remove the -fno-diagnostics-show-option flag). You can then disable this diagnostic completely by adding -Wno-extra-tokens (again, the "extra tokens" warning is an example), or turn it into a non-fatal warning by means of -Wno-error=extra-tokens.

    However, this specific error is not due to a warning and I can't find any option to disable errors (makes sense, since most errors are fatal).

    But to just truncate the integer value and not having to fix all the wrong uses of uint32_t just yet, you could use static_cast(reinterpret_cast(ptr)). Needless to say, this will still be wrong.

提交回复
热议问题