On Oct 17, 2010, at 12:05 PM, Kyle Sluder wrote: > On Oct 16, 2010, at 8:31 PM, Ken Tozier <kentoz...@comcast.net> wrote: > >> Hi >> >> 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. > > Here's the gcc manual on inline: http://gcc.gnu.org/onlinedocs/gcc/Inline.html > > Also, this isn't a Cocoa question. You might want to pick up a book on C.
non-static inlines can't actually be inlined because they may be called from elsewhere or have their addresses taken This is actually not always true. If you have an non-static inline in a header file, the compiler is pretty smart about it. You can see this in action if you generate the assembly and look it it. This: inline int five() { return 5; } will result in one load instruction with the constant '5' if used in a call context such as int i = five(); If you pass &five to something that takes an 'int (*)()', the compiler will generate a function body in memory and pass a pointer to it. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com