I am working on MacOS-X Lion with GCC 4.2. This code works, but I get a warning I would like fix:
#include
main()
{
char *args[] = {\"/b
I do not know why the accepted answer was selected, it does not remove any warnings when I run this code....
I cannot confirm on your specific platform, but adding casts to each string constant has made the warnings go away for me.
#include
main()
{
char* const args[] = {(char*)"/bin/ls", (char*)"-r", (char*)"-t", (char*)"-l", (char*) 0 };
execv("/bin/ls", args);
}
OR
#include
main()
{
char *args[] = {(char*)"/bin/ls", (char*)"-r", (char*)"-t", (char*)"-l", (char*) 0 };
execv("/bin/ls", args);
}
It may be overly verbose and annoying, but the warnings go away.
I'm running this on: g++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4