• 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: inline function problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inline function problems


  • Subject: Re: inline function problems
  • From: Greg Parker <email@hidden>
  • Date: Sun, 17 Oct 2010 13:04:25 -0700

On Oct 17, 2010, at 12:05 PM, Kyle Sluder wrote:
> On Oct 16, 2010, at 8:31 PM, Ken Tozier <email@hidden> wrote:
>>
>> I want to create some inline functions that are universally available within my app, but can't seem to get them working. If I define a set of inlines within a specific class, they compile, but If I take the same functions and move them to a dedicated "inlines" file and include that, it doesn't. The compiler spits out the following:
>>
>> _UtilScaleRectSize", referenced from:
>> -[MyView initWithContainer:frame:] in MyVieww.o
>> ld: symbol(s) not found
>> collect2: ld returned 1 exit status
>>
>> Here's what works when the inlines are defined for a specific class
>>
>> static inline void UtilScaleRectSize(NSRect inRect, float inScale)
>
> Think about this for a second: "static" means file scope, so obviously you can't reference the symbol from another file. And non-static inlines can't actually be inlined because they may be called from elsewhere or have their addresses taken. So inline is useless to you. Just use an appropriate -O option that does whole-program transformation.

A static inline function should work just fine. You need to define it in a header file, and include that header file everywhere you want to use it.

// inlines.h
static inline void UtilScaleRectSize(NSRect inRect, float inScale) {
    // your code here
}

// MyView.m
#include "inlines.h"
void fn(void) {
	UtilScaleRectSize(r, s);
}


Note that there is no inlines.m. If your code is structured like this, double-check that the #include is working as you expect (and not failing because of an include cycle or search path problem or precompiled header surprise). Open MyView.m and run Build > Preprocess. That will show you the file with all of the #includes resolved. You should be able to find your definition of UtilScaleRectSize() in the file, and the place you call it after that. If the definition is missing, or the call site is before the definition, then it'll fail.


--
Greg Parker     email@hidden     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >inline function problems (From: Ken Tozier <email@hidden>)
 >Re: inline function problems (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: How to create secondary Thread that listens to event taps?
  • Next by Date: Re: inline function problems
  • Previous by thread: Re: inline function problems
  • Next by thread: Re: inline function problems
  • Index(es):
    • Date
    • Thread