Karsten Blees <[email protected]> writes:
> Am 29.05.2014 12:47, schrieb Stepan Kasal:
>> Fix const warnings in http-fetch.c and remote-curl.c main() where is
>> argv declared as const.
>>
>> The fix should work for all future declarations of main, no matter
>> whether the second parameter's type is "char**", "const char**", or
>> "char *[]".
>
> I'm 100% in favor of a solution that doesn't restrict main to non-const
> char**! Thanks.
>
>> Signed-off-by: Stepan Kasal <[email protected]>
>> ---
>> compat/mingw.h | 5 +++--
>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/compat/mingw.h b/compat/mingw.h
>> index 15f0c9d..8745d19 100644
>> --- a/compat/mingw.h
>> +++ b/compat/mingw.h
>> @@ -369,10 +369,11 @@ extern CRITICAL_SECTION pinfo_cs;
>> void mingw_startup();
>> #define main(c,v) dummy_decl_mingw_main(); \
>> static int mingw_main(c,v); \
>> -int main(int argc, char **argv) \
>> +int main(c, char **main_argv_not_used) \
>> { \
>> + typedef v, **argv_type; \
>> mingw_startup(); \
>> - return mingw_main(__argc, __argv); \
>> + return mingw_main(__argc, (argv_type)__argv); \
>> } \
>> static int mingw_main(c,v)
>>
>
> I have to admit I had trouble understanding what 'typedef v,
> **arv_type;' does (looks invalid at first glance), and why you
> would need main_argv_not_used instead of just main(c,v).
>
> So, I'd like to award +10 points for cleverness, but -10 for
> obscurity ;-) Probably deserves a comment or an explanation in the
> commit message.
Agreed. The "typedef" one is a cute hack.
I am wondering why the solution is not a more obvious "drop const
that is not ANSI C", though. I only have a ready-access to N1570
draft but in it I find:
5.1.2.2.1 Program startup
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;10) or in some other implementation-defined manner.
---
10) Thus, int can be replaced by a typedef name defined as int,
or the type of argv can be written as char ** argv, and so on.
> A simpler solution that works with all definitions of main() is to
> cast to void* (tell the compiler all responsibility is on
> us).
Can you cast away the constness that way, though?
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html