Re: warning in main.m
Re: warning in main.m
- Subject: Re: warning in main.m
- From: matt neuburg <email@hidden>
- Date: Fri, 30 Apr 2004 10:04:34 -0700
Well, here we are again. In Xcode 1.2 I am again getting this warning when I
first compile a new Cocoa app project, because the template declares main's
second argument as char* and then passes it off to NSApplicationMain which
expects a const char*. I was sort of hoping that either the template or the
behavior of NSApplicationMain or the behavior of the compiler or something
would have been fixed... Of course this is no big deal, but I just thought
I'd mention it for the record. m.
On Sun, 4 Jan 2004 01:02:25 -0800, Eric Albert <email@hidden> said:
>At 8:46 PM -0500 12/30/03, Wayne Hasley wrote:
>>On 12/30/03 8:24 PM, "matt neuburg" <email@hidden> wrote:
>>
>>> // main.m
>>> #import <Cocoa/Cocoa.h>
>>> int main(int argc, char *argv[])
>>> {
>>> return NSApplicationMain(argc, argv); // warning here!
>>> }
>>>
>>> The warning reads: "passing arg 2 of
>>> `NSApplicationMain' from incompatible pointer type".
>>>
>>> What does this mean and how do I make it stop? Why is
>>> it happening all of a sudden like this? Thx - m.
>>
>>Arg 2 should be a const...
>>
>>Change it to:
>> int main(int argc, const char *argv[])
>> {
>> return NSApplicationMain(argc, argv); // warning here!
>> }
>
>Actually, argument 2 should not be const, and Xcode 1.1 is correct.
>The ISO C standard specifies that the second argument to main() is a
>char *[], not a const char *[]. Using a const char *[] by default is
>not really ideal because it implies an additional restriction on the
>second argument that the standard doesn't require.
>
>That leads to the second issue, which is the warning. GCC is
>actually somewhat nice in only warning for this rather than
>displaying an error. Converting a const char ** to a char ** is
>illegal in C because the allowed conversion from pointer-to-const-T
>to pointer-to-T doesn't apply recursively. See
><http://www.eskimo.com/~scs/C-faq/q11.10.html> for details.
>
>In other words, either the template should cast or NSApplicationMain
>should take a char *[] as its second argument, but the change in
>Xcode's template makes the template more standards-compliant. I'm
>not on any of the teams that are involved here, but I'd vote for
>NSApplicationMain being changed for the same reason as changing
>main.m was the right thing to do. I think we already have a bug
>report about that. :)
--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
AppleScript: the Definitive Guide! NOW SHIPPING...! (Finally.)
http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.