Re: Question about weak linking?
Re: Question about weak linking?
- Subject: Re: Question about weak linking?
- From: Trenton Schulz <email@hidden>
- Date: Fri, 7 May 2004 10:14:31 +0200
On May 7, 2004, at 2:00 AM, Glen Low wrote:
Trenton:
On 06/05/2004, at 3:33 PM, Trenton Schulz wrote:
Hi,
Someone from carbon-development suggest I pass this along to the
Xcode-Users list, so here you go:
Begin forwarded message:
Let's say I have this program where I'm trying to do weak linking:
#include <Carbon/Carbon.h>
void use_secure_keyboard(bool b)
{
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3)
if(b) {
if (EnableSecureEventInput)
EnableSecureEventInput();
} else {
if (DisableSecureEventInput)
DisableSecureEventInput();
}
#else
(void*)b;
#endif
}
int main()
{
use_secure_keyboard(true);
return 0;
}
Now if I compile this program as a C program it works fine. But if I
compile it as a C++ program I get this messages:
main.cpp: In function `void use_secure_keyboard(bool)':
main.cpp:7: warning: the address of `OSStatus
EnableSecureEventInput()', will
always be `true'
main.cpp:10: warning: the address of `OSStatus
DisableSecureEventInput()', will
always be `true'
And sure enough, if you run it on Jaguar it does crash.
I'm guessing it might possibly be the name mangling, but it comes
from Carbon so it should know EnableSecureEventInput is a C
function.
Is there anything obvious/non-obvious I'm missing? I really need to
this to work inside a C++ context.
Are the functions EnableSecureEventInput and DisableSecureEventInput
really weak-linked? You can check using nm -mg executable on the
command line.
Of course, what warning the compiler throws isn't _that_ big deal a
deal as long as the output is OK. nm gives me the same for both:
nm -mg weaklink.app/Contents/MacOS/weaklink|egrep "(Enable|Disable)"
9291c7d0 (prebound undefined) weak external _DisableSecureEventInput
(from Carbon)
9291bfe4 (prebound undefined) weak external _EnableSecureEventInput
(from Carbon)
So I guess its just g++ being silly. Though it makes me wonder if I
should assign it to a volatile variable as I'm curious if it will
optimize my check away in a release situation.
--
Trenton Schulz
Trolltech AS
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.