home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / mswindo / programm / misc / 4706 < prev    next >
Encoding:
Text File  |  1993-01-07  |  2.1 KB  |  61 lines

  1. Path: sparky!uunet!olivea!spool.mu.edu!uwm.edu!cs.utexas.edu!torn!nott!emr1!jagrant
  2. From: jagrant@emr1.emr.ca (John Grant)
  3. Newsgroups: comp.os.ms-windows.programmer.misc
  4. Subject: Re: difference between STUFF *stuff & STUFF stuff[]???
  5. Message-ID: <1993Jan7.202312.22886@emr1.emr.ca>
  6. Date: 7 Jan 93 20:23:12 GMT
  7. References: <1993Jan6.084522.25921@emr1.emr.ca> <726351962snz@chrism.demon.co.uk>
  8. Organization: Energy, Mines, and Resources, Ottawa
  9. Lines: 50
  10.  
  11. In article <726351962snz@chrism.demon.co.uk> chris@chrism.demon.co.uk writes:
  12. >In article <1993Jan6.084522.25921@emr1.emr.ca> jagrant@emr1.emr.ca writes:
  13. >
  14. >>At the risk of appearing stupid again, I have another (perhaps
  15. >>obvious, but not right now at 3:30 AM) question...
  16. >> [ Lots of stuff deleted]
  17. >>
  18. >>So, can someone tell me the difference between the following 2
  19. >>statements:
  20. >>        extern STUFF *stufftable;
  21. >>        extern STUFF stufftable[];
  22. >>with respect to the code generated when I reference stufftable, i.e.:
  23. >>        stufftable[i].xxx=...
  24. >>and explain why it is so dangerous here, but it's perfectly ok
  25. >>to use a pointer or a [] in a function declaration.
  26. >>-- 
  27. >>John A. Grant                                           jagrant@emr1.emr.ca
  28. >>Airborne Geophysics
  29. >>Geological Survey of Canada, Ottawa
  30. >>
  31. >
  32. >The difference is very simple:
  33. >
  34. >    extern STUFF *stufftable
  35. >
  36. >tells the complier that you have a global variable which is a POINTER to
  37. >a "stufftable".  ie, the global quantity is a 2 or 4-byte pointer.
  38. >
  39. >    extern STUFF stufftable[]
  40. >
  41. >tells the compiler that you have a global ARRAY of STUFFs.
  42. >
  43. >The two things are totally different.  The reason that it doesn't matter
  44. >in a function declaration is that passing the name of an array to a function
  45. >is the same as passing a pointer to the start of the array.
  46. >
  47. >Hope this helps,
  48.  
  49.  
  50.         Yes, it's me again and less stupid...
  51.         Thanks to all you responded.  The essential
  52.         difference is that:
  53.             extern STUFF stufftable[];
  54.         assumes that stufftable resides in the current
  55.         data segment, when in fact it is a pointer to
  56.         the stuff on the heap.
  57. -- 
  58. John A. Grant                        jagrant@emr1.emr.ca
  59. Airborne Geophysics
  60. Geological Survey of Canada, Ottawa
  61.