문제

I have a function:

int exploreDIR (char stringDIR[], char arguments[6][100])
{    
     /*stuff...*/
     execv(filePath, arguments); 
}

However, I get the warning: passing argument 2 of ‘execv’ from incompatible pointer type

If execv expects char* const argv[] for its second argument, why do I receive this warning?

Since arrays are essentially the same thing as pointers to the start of the array, what is the critical difference here between char arguments[][] and char* const argv[]?

도움이 되었습니까?

해결책

You are are passing a pointer (*) looking like this:

*
`-> aaaa...aaaabbbb...bbbbcccc...cccc

It points to memory containing several char[100] arrays.

The function expects an argument looking like this:

*
`->***
   ||`-> cccc...cccc
   |`-> bbbb...bbbb
   `-> aaaa...aaaa

It wants a pointer pointing to memory containing several char*.

The two types are different and cannot be automatically converted.

다른 팁

char arguments[6][100] is a 600-byte chunk of memory arranged into 6 100-byte segments, whereas char* argv[] is an array of pointers to segments of memory which could be anywhere. One way to see the difference: arguments[i+1] - arguments[i] will be 100, while argv[i+1] - argv[i] could be ANYTHING.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top