• 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: Obj-C language question: C function within @implementation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obj-C language question: C function within @implementation


  • Subject: Re: Obj-C language question: C function within @implementation
  • From: Henry McGilton <email@hidden>
  • Date: Thu, 3 Jul 2003 10:30:20 -0700

On Thursday, July 3, 2003, at 09:56 AM, daniel wrote:

The code compiles inside the @implementation block because of Apple's fairly recent (last couple years?) automatic "C <-> ObjC" bridging support.

It doesn't compile outside the @implementation block because there's no Obj-C runtime to associate with the message sends that are made within the function.

All in all, I'd say your poor, disparaged co-worker is probably doing something more or less correctly! :-)

Daniel

I have to say this is one of the more confused threads I have had
the misfortune to read in this group. I have this C function
*outside* the @implementation:

int orderSubviews(id firstView, id secondView, void *context)
{
BOOL firstSelected = [firstView selected];
BOOL secondSelected = [secondView selected];
int ordering = NSOrderedSame;

if ((firstSelected == YES) && (secondSelected == NO)) {
ordering = NSOrderedDescending;
} else if ((firstSelected == NO) && (secondSelected == YES)) {
ordering = NSOrderedAscending;
}
return ordering;
}

and it compiles and runs just fine. As Jeff Harrell recalls (correctly
in the context of NSArray sorting), this one is a C function for ordering subviews.
It gets called from *within* the @implementation block from an Objective-C method, thusly:

[tabBackdrop sortSubviewsUsingFunction: orderSubviews context: nil];

The only time I had a C function outside the block give me *warnings* was
the warning about the function accessing protected variables, and that this
warning would be a hard error in future. In that case, placing the C function
*inside* the @implementation block cured the warnings, obviating the need to
declare the instance variables as @public.

Best Wishes,
........ Henry



On Thursday, July 3, 2003, at 08:15 AM, Sean McBride wrote:

The error my coworker made (aside from step 3 itself :)) was to
accidentally put the C function within the @implementation block, and it
still compiles. I noticed this, and moved the C function out of the
@implementation block and it stopped compiling. I'm wondering if it
should never have compiled in the first place.

===============================+============================
Henry McGilton, Boulevardier | Trilithon Software
Objective-C/Java Composer | Seroia Research
-------------------------------+----------------------------
mailto:email@hidden | http://www.trilithon.com
|
===============================+============================
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Obj-C language question: C function within @implementation (From: daniel <email@hidden>)

  • Prev by Date: Re: Strong language about Cocoa and Qt
  • Next by Date: Re: Extending range of current edit in textView?
  • Previous by thread: Re: Obj-C language question: C function within @implementation
  • Next by thread: Re: Obj-C language question: C function within @implementation
  • Index(es):
    • Date
    • Thread