This simple snippet generates the "missing sentinel in function call" warning with g++ 4.7.0, both if compiled as Cand C++ source. I believe that it's an error of the compiler, as the final NULL
value is there.
#include <unistd.h>
int main() {
execlp("mkdir", "mkdir", "-p", "test", NULL);
return 0;
}
Am I right?
No, you're wrong.
In C++ NULL is something like 0
or 0L
and might be the same in C. If the type of that constant is smaller than a pointer then it is not safe to pass it to a variadic function, as the high bits will be filled with junk.
On Linux the execlp(1)
man page says:
The list of arguments must be terminated by a NULL pointer, and, since these are variadic functions, this pointer must be cast
(char *) NULL
.
i.e. to portably provide the sentinel you need to do:
execlp("mkdir", "mkdir", "-p", "test", (char*)NULL);
and this is what GCC is warning you about.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With