Thread View: comp.sys.next.programmer
3 messages
3 total messages
Started by Ian Flanigan
Fri, 21 Aug 1992 18:08
Is @selector(foo:) constant?
Author: Ian Flanigan
Date: Fri, 21 Aug 1992 18:08
Date: Fri, 21 Aug 1992 18:08
24 lines
1236 bytes
1236 bytes
Today I was trying to manually initialize an array that would associate a bunch
of selectors. I tried:
static unsigned int my_array[][3] =
{
{ 1, @selector(foo:), @selector(bar) },
...
}
The compiler came back and said:
initializer for static variable is not constant
So I tried making it non-static. No good. (Didn't think it would help :-) It
therefore appears that @selector(foo:) does not generate something constant.
Does anyone know what it _does_ generate? Anyone have a better idea than to
use strings and sel_getUid() instead?
Thanks.
--
Ian Flanigan "You can never have too many napkins."
Project Zeus
Washington University in St. Louis
flan@starling.wustl.edu
Re: Is @selector(foo:) constant?
Author: Mike Dixon
Date: Sat, 22 Aug 1992 00:42
Date: Sat, 22 Aug 1992 00:42
32 lines
1260 bytes
1260 bytes
> I tried:
>
> static unsigned int my_array[][3] =
> {
> { 1, @selector(foo:), @selector(bar) },
> ...
> }
>
> The compiler came back and said:
> initializer for static variable is not constant
the trick is that although @selector(foo:) isn't constant, &@selector(foo:)
is. initialize your array with the addresses of the selectors, and
remember to dereference them before you use them. for example, here's
some code from XText:
typedef struct {
SEL *sel;
short arg1;
short arg2;
keyCode key;
} tbl_entry;
const tbl_entry emacs_base[] = {
{&@selector(moveChar:mode:), -1, 0, 0x351}, // ctrl-b move back char
{&@selector(moveChar:mode:), -1, 1, 0x401}, // ctrl-h delete back char
... etc.
--
.mike.
Re: Is @selector(foo:) constant?
Author: Mike Dixon
Date: Tue, 25 Aug 1992 21:35
Date: Tue, 25 Aug 1992 21:35
19 lines
1200 bytes
1200 bytes
** 3.0 Incompatibility Alert! **
a few days ago i wrote:
the trick is that although @selector(foo:) isn't constant,
&@selector(foo:) is. initialize your array with the addresses of
the selectors, and remember to dereference them before you use
them.
while this was true in 2.0, a new version of the TextORama MiniExample
that appeared today in the archives suggests that it's no longer true
in 3.0 (i'm not a beta tester, so i can't confirm it). it appears
that even the addresses of @selector expressions are no longer
constant; to make this kind of code work in 3.0 you'll have to build
the array at runtime (with calls to sel_getUid -- see the new
TextORama for details).
--
.mike.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads