home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.next.programmer
- Path: sparky!uunet!decwrl!parc!mdixon
- From: mdixon@parc.xerox.com (Mike Dixon)
- Subject: Re: Is @selector(foo:) constant?
- Message-ID: <mdixon.714444125@thelonius>
- Keywords: @selector, Objective-C, constant
- Sender: news@parc.xerox.com
- Organization: Xerox PARC
- References: <1992Aug21.180854.24973@wuecl.wustl.edu>
- Date: 22 Aug 92 00:42:05 GMT
- Lines: 32
-
- > 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.
-