home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / next / programm / 5233 < prev    next >
Encoding:
Text File  |  1992-07-25  |  1.8 KB  |  62 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!psinntp!cgrafx!msb
  3. From: msb@chromagrafx.com (Michael S. Barthelemy)
  4. Subject: Re: Stupid question:  What does ** mean?
  5. Message-ID: <1992Jul24.133729.2290@chromagrafx.com>
  6. Sender: msb@chromagrafx.com
  7. Organization: Chromagrafx Imaging Systems, Hauppauge, NY
  8. References: <1992Jul22.225838.13892@vlsisj.uucp>
  9. Date: Fri, 24 Jul 1992 13:37:29 GMT
  10. Lines: 50
  11.  
  12. In article <1992Jul22.225838.13892@vlsisj.uucp>  
  13. smadsen@leland.Stanford.EDU (Steve Madsen) writes:
  14. > Here's an easy one. . .I'm stumped by the double asterisk declaration, 
  15. > for example:
  16. > (int **)
  17. > I've tried to locate it in Chapter 3, 6 and 7 of NextStep Concepts, as 
  18. > well as two different C manuals, so it's not a pure RTFM question (I 
  19. > hope). . .
  20.  
  21. It's a double pointer.  (i.e. A pointer to another pointer.)  If you were  
  22. to write:
  23.  
  24.     int    **temp;
  25.  
  26. It can be referenced several ways though.
  27.  
  28.     temp[x] would give you the x'th element of the pointer array.
  29.         (which would be another pointer)
  30.  
  31.     temp would give you the first element (pointer)
  32.         (such that temp has not been changed)
  33.  
  34. When mallocing one of these structures by yourself you will have to first  
  35. malloc for the first pointer to the array and then malloc off all of the  
  36. pointers to fill the array:
  37.  
  38. extern struct foo;
  39. extern int numElements;
  40. struct foo **fooItems;
  41.  
  42. {
  43.     int i;
  44.  
  45.     fooItems = (struct foo **) malloc(sizeof(struct foo *) *  
  46. numElements);
  47.     for (i = 0; i < numElements; i++)
  48.         fooItems[i] = (struct foo *) malloc(sizeof(struct foo));
  49. }
  50.  
  51. You can procede down the pointer path a long ways.  The most I have ever  
  52. used are five and I am not sure if there is a limitation as to how many  
  53. one can have.
  54.  
  55. It happens to be referenced on pages 107-110 in K&R but they do not use a  
  56. terribly good example to show a double pointer.
  57.  
  58. Mike Barthelemy
  59. msb@chromagrafx.com
  60.