home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / next / programm / 5742 < prev    next >
Encoding:
Text File  |  1992-08-21  |  1.2 KB  |  45 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!decwrl!parc!mdixon
  3. From: mdixon@parc.xerox.com (Mike Dixon)
  4. Subject: Re: Is @selector(foo:) constant?
  5. Message-ID: <mdixon.714444125@thelonius>
  6. Keywords: @selector, Objective-C, constant
  7. Sender: news@parc.xerox.com
  8. Organization: Xerox PARC
  9. References: <1992Aug21.180854.24973@wuecl.wustl.edu>
  10. Date: 22 Aug 92 00:42:05 GMT
  11. Lines: 32
  12.  
  13. >    I tried:
  14. >
  15. >    static unsigned int my_array[][3] =
  16. >    {
  17. >       { 1, @selector(foo:), @selector(bar) },
  18. >       ...
  19. >        }
  20. >
  21. >    The compiler came back and said:
  22. >       initializer for static variable is not constant
  23.  
  24. the trick is that although @selector(foo:) isn't constant, &@selector(foo:)
  25. is.  initialize your array with the addresses of the selectors, and
  26. remember to dereference them before you use them.  for example, here's
  27. some code from XText:
  28.  
  29.   typedef struct {
  30.       SEL   *sel;
  31.       short arg1;
  32.       short arg2;
  33.       keyCode key;
  34.   } tbl_entry;
  35.  
  36.   const tbl_entry emacs_base[] = {
  37.     {&@selector(moveChar:mode:), -1,  0, 0x351},  // ctrl-b    move back char
  38.     {&@selector(moveChar:mode:), -1,  1, 0x401},  // ctrl-h  delete back char
  39.  
  40.                 ... etc.
  41.  
  42. --
  43.  
  44.                                              .mike.
  45.