Re: Just starting off in obj C
Re: Just starting off in obj C
- Subject: Re: Just starting off in obj C
- From: Bill Bumgarner <email@hidden>
- Date: Fri, 24 Oct 2008 23:48:14 -0700
On Oct 24, 2008, at 10:57 PM, Ian Joyner wrote:
I didn't really mean lazy in that sense. Dynamic binding is
desirable and by design. Rather that C compilers require a call
operator '()' to tell them what to do, whereas other languages work
that out (except COBOL and FORTRAN which need CALL). And things like
dereferencing either by '.' or '->' because C compilers can't be
bothered seeing if the variable is simple or pointer. Call is the
common case, generating a function reference is the rare case
(especially in OO languages, which at least hides this
implementation in dispatch tables). Loads of other junk in there
that makes C a verbose language that exposes implementation and
increases software brittleness.
Nothing about the original poster's question had to do with dynamic
binding; it was entirely focused on C's rather anal type
requirements and the lack of type checking in one particular case.
So anal, in fact, that dereferencing via "." vs. "->" mean entirely
different things; the difference between the two is rather quite
extremely critical to understanding what a piece of C code is doing.
This has nothing to do with the compiler being lazy and everything to
do with the rather anal requirements of C.
There is exactly one problem in the original poster's example; NSLog
doesn't check the arguments passed to it against the format string
and, hence, the crash occurred.
If the original poster had used fprintf() (without the %@ specifier),
the compiler very much would have complained:
#include <stdio.h>
int x() { return 42; }
int main(int argc, char **argv) {
printf("%d\n", x);
return 0;
}
cc -Wall of the above spews:
foo.c:6: warning: format ‘%d’ expects type ‘int’, but argument 2 has
type ‘int (*)()’
NSLog simply doesn't check its arguments. It is a bug. Or, not a
bug, it is simply a feature not yet implemented.
As for brittleness, yup -- C *can* be brittle if you abuse typecasting
and ignore compiler warnings. But, from a compilation standpoint, it
is actually not brittle at all. Where C -- and legacy Objective-C --
becomes brittle is in changes over time; a seemingly innocuous change
may require extensive recompilation to work.
b.bum
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden