Re: inline function problems
Re: inline function problems
- Subject: Re: inline function problems
- From: Velocityboy <email@hidden>
- Date: Sun, 17 Oct 2010 14:30:15 -0700
On Oct 17, 2010, at 2:07 PM, Kyle Sluder wrote:
> On Sun, Oct 17, 2010 at 1:29 PM, Velocityboy <email@hidden> wrote:
>> 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:
>
> IIRC there's no guarantee that a two references to the same non-static
> inline function will have the same address even within the same
> translation unit, depending on optimization level, order of appearance
> in the source file, and context in the call site. But that might be a
> Microsoftism, or just a complete fabrication of my mind.
>
> --Kyle Sluder
Actually it's worse than that - I went back and looked again and when the compiler converts an inline into a non-inline function for the purposes of getting a pointer to it, the function it creates is not anonymous. So if you take the address of an inline in more than once translation unit, you end up with a multiply defined symbol at link time.
I haven't ever come across this situation in non-hypothetical code, so I don't remember what the spec has to say about it, and I don't have a copy handy. Moral of the story is that it's not safe to take the address of an inline.
_______________________________________________
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