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.
huffenc
takes achar *
, but you're passing it achar const *
... – Urticationconst
. – Scutehuffenc
needs a non-const pointer, and change it to const if possible. – Urticationmain
anyway, just do it right to begin with;int main(int argc, char *argv[])
. – Oriflammeconst
pretty much anywhere as you want. – Elmiraelmoint main(int argc, char *argv[])
orint main(void)
. It goes on to say that "5.1.2.2.1 Program startup: The parameters argc and argv and the strings pointed to by the argv array shall be modifiable by the program..." So, I would call it incorrect. It will work of course, but why? When have either of the two standard definitions led to buggy programs? – Oriflammeint main(int, const char**)
may not be elegant, but it is definitely not "incorrect" (it's just the word that I don't like). – Elmiraelmomain
(quoted above by Ed S.). It doesn't say anywhere that you can arbitrarily addconst
, and I'm not at all sure that a conforming compiler is required to accept it if you do. If you have an argument that addingconst
is valid (i.e., must be accepted by any conforming hosted C compiler), I'd be interested in seeing it. (Just noticed how hold this question is; not sure why it showed up on the front page for me.) – Mchugh