Question

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[]?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top