Re: warning in main.m
Re: warning in main.m
- Subject: Re: warning in main.m
- From: Kevin Grant <email@hidden>
- Date: Fri, 2 Jan 2004 12:55:15 -0600
I'm a newbie to Objective C, and to C for that matter, so this may be
a dumb
question, but what is being declared here? Is it
(1) a variable array whose name is "argv[]" and whose type is
"const char *", as in "constant character pointer"?
or is it
(2) a variable array whose de-referenced name is "*argv[]" and whose
type is
"const char"?
If it is the first, which I think it is, then shouldn't the template
for
main's declaration put a space between the asterisk and the variable
name,
like this?
int main(int argc, const char * argv[])
The C syntax requires the "[]" after the name (whereas Java does not),
but really it is associated with the *type*. So the name is just
"argv". The type is "char const*[]", a pointer to an array containing
pointers to immutable characters; that is to say, you can change the
value of any pointer in the array, but you cannot change the value of
the thing it points to.
The reason for gluing the * to the variable, at least for some people,
is to avoid these kinds of oversights that C allows:
char* x, y;
...which actually declares "x" to be "char*", but y to be a plain
"char". The obvious work-around is just to never be lazy and use the
comma operator this way. :)
FWIW I believe Xcode is now declaring argv correctly in terms of const
versus non-const. There are legitimate reasons to want the argument
strings in the array to be mutable - although most applications
probably do not require this.
Kevin G.
http://homepage.mac.com/kmg/
mail to kevin at ieee dot org
_______________________________________________
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.