MSVC emits warning C4090 about const correctness while both GCC and Clang accept it: Compiler Explorer .
void dummy(void)
{
int i[42];
int *pi[42];
int const *pci[42];
memset(i, 0, sizeof i);
memset(pi, 0, sizeof pi);
memset(pci, 0, sizeof pci); // warning C4090: 'function': different 'const' qualifiers
}
It seems MSVC treats pci
as constant when it's not.
This bug is apparently awfully old . Any idea how to fix this without turning C4090 off?
You can disable this warning right before the line which invokes it and restore it back afterwards https://godbolt.org/z/W-XR-Q :
#include <string.h>
void dummy(void)
{
int i[42];
int *pi[42];
const int *pci[42];
memset(i, 0, sizeof i);
memset(pi, 0, sizeof pi);
#pragma warning( push )
#pragma warning( disable : 4090)
memset(pci, 0, sizeof pci); // NO warning C4090
#pragma warning( pop )
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.