我无法理解这个编译器警告。我对strncmp
的实现工作正常,但在编译时我会收到警告:
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){
我的实现方式如下:
static const char* builtIns[] = {"string1", "string2", "string3", "string4"};
void sampleFunction(char *argv[]) {
if(strncmp(argv[0], builtIns[2], sizeof(builtIns[2]))==0){
... do something ...
}
非常感谢任何有关正确实施strncmp
应该是什么的建议!