home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19226 < prev    next >
Encoding:
Text File  |  1993-01-05  |  1.5 KB  |  56 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!psinntp!sugar!martink
  3. From: martink@NeoSoft.com (Martin Koistinen)
  4. Subject: ** in C
  5. Organization: NeoSoft Communications Services -- (713) 684-5900
  6. Date: Tue, 5 Jan 1993 03:49:03 GMT
  7. Message-ID: <C0D3xs.1y2@NeoSoft.com>
  8. Lines: 46
  9.  
  10. I have a function that needs a 2D array. So I declared it as follows:
  11.  
  12. double *My_Function(double A[3][3])
  13. {
  14.     static double R[3];
  15.       .
  16.       .
  17.       .
  18.    return((double *)&R);
  19. }
  20.  
  21. I have a header file that declares it as:
  22.  
  23. double *My_Function(double **)
  24.  
  25. My code refers to it as:
  26.  
  27. double M[3][3];
  28. double *p;
  29.  
  30. p = My_Function(M);
  31.  
  32. I have two questions:
  33.  
  34. 1) Is there any reason why I shouldn't return a pointer to a static from a
  35. function? I realize that I may get bad results if I try to reference the
  36. pointeaafter I do another call to the function or try to use it twice in
  37. the same statement but is there anything else?
  38.  
  39. 2) My compiler gives me a warning that I am passing the function something
  40. other then what it wants. Why?
  41.  
  42. My code seems to work great but I feel better when my compiler doesn't
  43. give me warnings. It was my understanding that n Dimensional arrays break
  44. down into pointers (n references).
  45.  
  46. I am curious about the static stuff because I have never seen this done by
  47. others.
  48.  
  49. Please respond via email - Thanks
  50. Martink@neosoft.com
  51. -- 
  52. ______
  53. \    / 95 percent of the symbols used in this | Martin J. Koistinen
  54.  \  /  post were made of recycled  characters | martink@neosoft.com
  55.   \/   ----------- Recycle today for tomorrows future -------------
  56.