• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Just starting off in obj C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Just starting off in obj C
      • From: Ian Joyner <email@hidden>
    • Re: Just starting off in obj C
      • From: Chris Idou <email@hidden>
    • Re: Just starting off in obj C
      • From: Philip Aker <email@hidden>
References: 
 >Just starting off in obj C (From: Michael <email@hidden>)
 >Re: Just starting off in obj C (From: Paul Russell <email@hidden>)
 >Re: Just starting off in obj C (From: Alexander von Below <email@hidden>)
 >Re: Just starting off in obj C (From: Ian Joyner <email@hidden>)
 >Re: Just starting off in obj C (From: Bill Bumgarner <email@hidden>)
 >Re: Just starting off in obj C (From: Ian Joyner <email@hidden>)

  • Prev by Date: Re: Console littered by Xcode 3.1.1 garbage collection messages
  • Next by Date: Re: Just starting off in obj C
  • Previous by thread: Re: Just starting off in obj C
  • Next by thread: Re: Just starting off in obj C
  • Index(es):
    • Date
    • Thread