Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Argument 1 discards qualifiers from pointer target type

Tags:

c

main

argv

My main function is as follows:

int main(int argc, char const *argv[])
{
    huffenc(argv[1]);
    return 0;
}

The compiler returns the warning:

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

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

What could this warning mean?

like image 925
Alex Nichols Avatar asked Mar 13 '13 23:03

Alex Nichols


1 Answers

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 5.1.2.2.1 (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.

like image 108
Ed S. Avatar answered Oct 19 '22 08:10

Ed S.