If I have a function:
void myfunction(char** s);
Then I can pass a char* like this:
char* s = malloc(100);
myfunction(&s);
But my compiler won’t allow me to do this:
char s[100] = {0};
myfunction(&s);
I thought that a pointer to the buffer should be allowed by the compiler.
Your function expects a pointer to a pointer (
char **). You are trying to pass a pointer to an array instead (char (*)[100]). Why do you expect this to “be allowed by the compiler”? Arrays are not pointers. Arrays and pointers are objects of completely different nature. A pointer to a pointer is not in any way compatible with a pointer to an array. You can’t use them interchangeably.If you want you use your array-based buffer with a function that expects
char **, you have to explicitly create a pointer to that buffer firstand then pass a pointer to that pointer, as you did before