Help with getopts_long()

I'm trying to use getopts_long to process command line arguments. I need to setup an option array to pass to getOpts_long. But when I compile I get the error

wbadinitl: String literal converted to char* in initialization


1
2
3
4
5
6
7
8
9
10
    static struct option long_options[] =
        {
            {"first-page", required_argument, 0, 'f'},
            {"add",     no_argument,       0, 'a'},
            {"append",  no_argument,       0, 'b'},
            {"delete",  required_argument, 0, 'd'},
            {"create",  required_argument, 0, 'c'},
            {"file",    required_argument, 0, 'f'},
            {0, 0, 0, 0}
        };


Thanks for any help.
Tha only way I can get around with is by doing

1
2
string FirstPageString = "first-page";
char *firstPageCharPointer = (char*) stringFirstPage.c_str();


But this is making the my code very verbose. Is their any way around this.
1
2
3
4
5
6
7
//getopt.h
struct option {
    const char *name;
    int         has_arg;
    int        *flag;
    int         val;
};
I don't understand why are you getting that error. The definition ask for a const char *.
gcc 4.4.3 doesn't complain.
{(char*) "verbosity", required_argument, 0, 'v'},

It works if I cast it.

Thanks.
Disch wrote:
Don't cast around compiler errors. If the compiler complains without the cast, it means you're doing something wrong. Casting does not fix the problem, it just shuts the compiler up.
If it is asking for a char * it may want to modify the content
(it doesn't make sense, but ¿why doesn't ask for const char * then?).
Last edited on
Topic archived. No new replies allowed.