Edwin
Edwin

Reputation: 562

warning: 'long_opts' may be used uninitialised in this function [-Wmaybe-uninitialised]

So I've been given this code that I'm supposed to work into my code which reads options from the command line using the getopt_long() function and passes them through a switch menu. The problem lies in that function, whereby if I don't initialise the value of long_opts I receive the following error:

error: 'long_opts' undeclared (first use in this function)

whereas if I do indeed initialise its value, I receive the error in the title:

warning: 'long_opts' may be used uninitialised in this function [-Wmaybe-uninitialised]

At the moment I'm wondering what the lesser of two evils might be because I absolutely cannot find a solution.

Upvotes: 0

Views: 89

Answers (1)

Ivan Ivanovich
Ivan Ivanovich

Reputation: 946

if you are using an uninitialized structure, then initialize it like this:

static struct option long_options[] = { {"add", required_argument, 0, 0 }, {"append", no_argument, 0, 0 }, {"delete", required_argument, 0, 0 }, {"verbose", no_argument, 0, 0 }, {"create", required_argument, 0, 'c'}, {"file", required_argument, 0, 0 }, {0, 0, 0, 0 } };

show your code please

error: 'long_opts' undeclared

this error appears if you are not declare a variable and use it in function.

warning: 'long_opts' may be used uninitialised in this function

this is not error, it is "warning" and this warning appears if you are declare var or struct, but do not initialize it and try to use it in function or expression but value of these var or struct is not define

Upvotes: 1

Related Questions