警告:'strncmp'调用中'sizeof'的参数与第二个源的表达式相同

时间:2014-10-26 08:20:52

标签: c++

我无法理解这个编译器警告。我对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应该是什么的建议!

0 个答案:

没有答案