Reputation: 3040
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 ?
Upvotes: 2
Views: 269
Reputation: 6875
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 )
}
Upvotes: 3