[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing Selectors

From: David Ayers
Subject: Re: Comparing Selectors
Date: Fri, 05 Aug 2005 11:58:13 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; rv:1.7.8) Gecko/20050513 Debian/1.7.8-1

Sašo Kiselkov schrieb:
> I have an issue with comparing selectors. Trouble is, the GNU Objective-C
> runtime tells me that SEL's are pointers to struct objc_selector and that they
> themselves may not be unique, and the correct way to compare them is by doing:
> sel1->sel_id == sel2->sel_id
> However, Apple forums and according to what I read about the Apple Objective-C
> runtime, doing just
> sel1 == sel2
> is perfectly fine and that the uniqueness of both selectors is ensured.
> So please, can anybody tell me what is the correct, civilized and portable way
> of doing it?

Indeed, for the Apple/NeXT Objective-C runtime selector equality can
determined by pointer comparison yet this does not work for the GNU
Objective-C runtime due to the notion of "typed selectors".  The
canonical way to portably compare selectors is to use

BOOL sel_eq (SEL s1, SEL s2)

which is actually a GNU Objective-C runtime function but GNUstep defines:

#define sel_eq(s1, s2)                  (s1 == s2)

for the Apple/NeXT Objective-C runtime in GNUstepBase/objc-gnu2next.h
which is included by GNUstepBase/GSObjCRuntime.h.  This last header
contains various functions to help abstract the differences between the
two runtimes, and is probably the header you want to include.  (Note
that not all mappings in objc-gnu2next.h really work smoothly due to
slightly differing semantics.)

David Ayers

reply via email to

[Prev in Thread] Current Thread [Next in Thread]