Avoiding casing away a const qualifier on a string literal

Ok, using GNU C++ 4.2.1, I can't figure out how to modify this program to not warn and not use a cast... is it even possible to do anymore? I really hate to cast away a const qualifier even when I know it's harmless to do so.

1
2
3
4
5
6
7
8
9
10
#include <unistd.h>

int main(int argc, char **argv)
{
        char * av[2];

        av[0]="/bin/ls";
        av[1]=NULL;
        execv(av[0], av);
}

Last edited on
How about this
1
2
3
4
5
6
7
8
9
10
11
#include <unistd.h>

int main(int argc, char **argv)
{
        char * av[2];
	char cmd[] = "/bin/ls";

        av[0]= cmd;
        av[1]=NULL;
        execv(av[0], av);
}

That works, thanks.

(Still feels like cheating though. :-)
Topic archived. No new replies allowed.