I am having trouble understanding this compiler warning. My implementation of strncmp
works fine but at compile time I am given a warning along the lines of:
tsh.c:87:41: warning: argument to ‘sizeof’ in ‘strncmp’ call is the same expression as the second source; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]
strncmp(argv[0], builtIns[1], sizeof(builtIns[1]))==0){
where my implementation is something along the lines of:
static const char* builtIns[] = {"string1", "string2", "string3", "string4"};
void sampleFunction(char *argv[]) {
if(strncmp(argv[0], builtIns[2], sizeof(builtIns[2]))==0){
... do something ...
}
Any advice on what the proper implementation of strncmp
should be is greatly appreciated!