Professional Web Applications Themes

Objective C -> C - Mac Programming

1) Is there a good book for C programmers to be able to read Objective C code examples? I just want to know the basics for translation. 2) I'm trying to translate some code to C and am scratching my head a few places. Here are the mysterious lines to me (not the entire function): before the function: - (IBAction) Install:(id)sender inside the function: NSBundle*myBundle = [NSBundle mainBundle]; NSString*path = [myBundle pathForResource:"theDataFork" ofType:"rsrc"]; NSURL *urlRef = [[NSURL alloc] initFileURLWithPath:path]; I have no idea what the line before the function means. My guess on the first line inside the function: CFBundleRef ...

  1. #1

    Default Objective C -> C

    1) Is there a good book for C programmers to be able to read Objective C
    code examples? I just want to know the basics for translation.

    2) I'm trying to translate some code to C and am scratching my head a few
    places. Here are the mysterious lines to me (not the entire function):

    before the function:
    - (IBAction) Install:(id)sender

    inside the function:

    NSBundle*myBundle = [NSBundle mainBundle];

    NSString*path = [myBundle pathForResource:"theDataFork" ofType:"rsrc"];
    NSURL *urlRef = [[NSURL alloc] initFileURLWithPath:path];


    I have no idea what the line before the function means.
    My guess on the first line inside the function:

    CFBundleRef myBundle = CFBundleGetMainBundle();

    for the next two, combine to one call:

    CFURLRef urlRef =
    CFBundleCopyResourceURL(myBundle,CFSTR("theDataFor k"),CFSTR("rsrc"),NULL);

    though perhaps a CFURLCreate... function is correct, I don't know, but that
    gets into CFAllocators.

    Thanks for any insight.

    -- Mac program, CW8 in C

    Bruce Coughlin Guest

  2. #2

    Default Re: Objective C -> C

    In <BB7A8FFF.ADE%brucecoughlinnyc.rr.com> Bruce Coughlin wrote:
    > 1) Is there a good book for C programmers to be able to read Objective
    > C code examples?
    An excellent book is on your computer. In fact, the book on Objective-C
    on your computer is one of the best computer books I've ever read, on
    any subject.
    > I just want to know the basics for translation
    There is no "translation". Objective-C is a C superset, not C in French.
    > 2) I'm trying to translate some code to C and am scratching my head a
    > few places
    Because you don't know Objective-C. Learn it. It takes about an hour. m.

    --
    matt neuburg, phd = [email]matttidbits.com[/email], [url]http://www.tidbits.com/matt[/url]
    REALbasic: The Definitive Guide! 2nd edition!
    [url]http://www.amazon.com/exec/obidos/ASIN/0596001770/somethingsbymatt[/url]
    Subscribe to TidBITS. It's free and smart.
    matt neuburg Guest

  3. #3

    Default Re: Objective C -> C

    Bruce Coughlin <brucecoughlinnyc.rr.com> wrote:
    > 1) Is there a good book for C programmers to be able to read Objective C
    > code examples? I just want to know the basics for translation.
    >
    > 2) I'm trying to translate some code to C and am scratching my head a few
    > places. Here are the mysterious lines to me (not the entire function):
    >
    > before the function:
    > - (IBAction) Install:(id)sender
    >
    > inside the function:
    >
    > NSBundle*myBundle = [NSBundle mainBundle];
    >
    > NSString*path = [myBundle pathForResource:"theDataFork" ofType:"rsrc"];
    > NSURL *urlRef = [[NSURL alloc] initFileURLWithPath:path];
    >
    >
    > I have no idea what the line before the function means.
    > My guess on the first line inside the function:
    >
    > CFBundleRef myBundle = CFBundleGetMainBundle();
    >
    > for the next two, combine to one call:
    >
    > CFURLRef urlRef =
    > CFBundleCopyResourceURL(myBundle,CFSTR("theDataFor k"),CFSTR("rsrc"),NULL);
    >
    > though perhaps a CFURLCreate... function is correct, I don't know, but that
    > gets into CFAllocators.
    >
    > Thanks for any insight.
    >
    > -- Mac program, CW8 in C
    Much of the Cocoa Foundation is 'toll-free bridged' with CoreFoundation
    objects, so you're generally right to make the assumptions about
    CFWhatever.

    That said, you can install the Apple Developer Tools and compile
    Objective-C/Cocoa programs. All for free, without translating it to
    CoreFoundation.

    My advice: Install the dev tools, learn enough Cocoa that you know an
    IBAction and an id are, and then do the translation. You might find that
    you've lost all momentum toward translating it to CoreFoundation, since
    Cocoa does all the heavy lifting for you.
    Paul Mitchum Guest

  4. #4

    Default Re: Objective C -> C

    > My advice: Install the dev tools, learn enough Cocoa that you know an
    > IBAction and an id are, and then do the translation. You might find that
    > you've lost all momentum toward translating it to CoreFoundation, since
    > Cocoa does all the heavy lifting for you.
    Oooo you might be right, but this is a very small function in a much larger
    (finished) C program. For future apps you're probably correct.

    brucecoughlin Guest

  5. #5

    Default Re: Objective C -> C

    In article <BB7A8FFF.ADE%brucecoughlinnyc.rr.com>,
    Bruce Coughlin <brucecoughlinnyc.rr.com> wrote:
    > 1) Is there a good book for C programmers to be able to read Objective C
    > code examples? I just want to know the basics for translation.
    I like the Hillegas book: "Cocoa Programming for Max OS X". "The Vermont
    Recipes" are also good, and was available free online.
    <http://www.stepwise.com/Articles/VermontRecipes/>

    For free, you can get:
    Inside Mac OS X: Object-Oriented Programming and the Objective-C
    Language, Apple's Objective-C doentation
    <http://developer.apple.com/techpubs/macosx/Cocoa/ObjectiveC/ObjC.pdf>

    It is probably already on your machine in
    /Developer/Doentation/Cocoa/ObjectiveC/
    > 2) I'm trying to translate some code to C and am scratching my head a few
    > places. Here are the mysterious lines to me (not the entire function):
    >
    > before the function:
    > - (IBAction) Install:(id)sender
    > I have no idea what the line before the function means.
    think:

    extern IBAction Install(id sender);

    and you won't be far wrong.
    David Phillip Oster Guest

  6. #6

    Default Re: Objective C -> C

    Bruce Coughlin <brucecoughlinnyc.rr.com> wrote in message news:<BB7A8FFF.ADE%brucecoughlinnyc.rr.com>...
    > 1) Is there a good book for C programmers to be able to read Objective C
    > code examples? I just want to know the basics for translation.
    I second the recommendation for "The Objective C Programming Language"
    on your computer.

    However, your problem seems to be more converting between Cocoa and
    Carbon, which is beyond the difference between Objectve C and C.
    In many cases there isn't a 1-to-1 translation between Cocoa and Carbon,
    though sometimes you can get close. Primarily, though, they're very
    different beasts. The Cocoa objects, which are provided in Objective C
    and Java, provide a lot of compact functionality which takes a lot more
    lines in Carbon.
    > before the function:
    > - (IBAction) Install:(id)sender
    This is the header; it's how Cocoa methods are declared. The minus sign
    means it's an instance method, as opposed to a class method. If you
    know C++, it corresponds roughly to

    IBAction Foo::Install(id sender)

    Except that IBAction, which is basically typedefed as void, also tells
    the compiler that this can be linked as an action with a NIB file.
    Eric Pepke Guest

  7. #7

    Default Re: Objective C -> C

    On Tue, 02 Sep 2003, Bruce Coughlin wrote:
    > 1) Is there a good book for C programmers to be able to read
    > Objective C code examples? I just want to know the basics for
    > translation.
    >
    Of course, as others have pointed out, the Objective-C manual that comes
    with the developers tools is one place to start.

    It might help to know that Objective-C ~=~ C + Smalltalk. That is, if
    you understand both Smalltalk and C, you'll find individual statements
    easy to read.

    I don't know if there's an option on the compiler, but Objective-C is
    (or used to be) translated into C as the first step in compilation -- so
    if you can get the output of that pass, your job is done for you.

    Of course, if you're doing the translation in order to port the code,
    you've got a problem, as the Cocoa frameworks are probably most of the
    code in most applications.

    Otherwise, why translate it?

    joe
    Joe Davison Guest

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139