Alex Nichols Alex Nichols - 1 year ago 223
C Question

Passing Argument 1 discards qualifiers from pointer target type

My main function is as follows:

int main(int argc, char const *argv[])
return 0;

The compiler returns the warning:

huffenc.c:76: warning: passing argument 1 of ‘huffenc’ discards qualifiers from pointer target type

For reference,
takes a
input, and the function is executed, with the sample input "senselessness" via
./huffenc senselessness

What could this warning mean?

Answer Source

It means that you're passing a const argument to a function which takes a non-const argument, which is potentially bad for obvious reasons.

huffenc probably doesn't need a non-const argument, so it should take a const char*. However, your definition of main is non-standard.

The C99 standard Section (Program startup) states:

The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):

int main(int argc, char *argv[]) { /* ... */ }

or equivalent;9) or in some other implementation-defined manner.

And goes on to say...

...The parameters argc and argv and the strings pointed to by the argv array shall be modifiable by the program, and retain their last-stored values between program startup and program termination.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download