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

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. From: chris@chrism.demon.co.uk (Chris Marriott)
  3. Path: sparky!uunet!pipex!demon!chrism.demon.co.uk!chris
  4. Subject: Re: difference between STUFF *stuff & STUFF stuff[]??? 
  5. Distribution: world
  6. References: <1993Jan6.084522.25921@emr1.emr.ca>
  7. Organization: None
  8. Reply-To: chris@chrism.demon.co.uk
  9. X-Mailer: Simple NEWS 1.90 (ka9q DIS 1.19)
  10. Lines: 44
  11. Date: Wed, 6 Jan 1993 20:26:02 +0000
  12. Message-ID: <726351962snz@chrism.demon.co.uk>
  13. Sender: usenet@demon.co.uk
  14.  
  15. In article <1993Jan6.084522.25921@emr1.emr.ca> jagrant@emr1.emr.ca writes:
  16.  
  17. >At the risk of appearing stupid again, I have another (perhaps
  18. >obvious, but not right now at 3:30 AM) question...
  19. > [ Lots of stuff deleted]
  20. >
  21. >So, can someone tell me the difference between the following 2
  22. >statements:
  23. >        extern STUFF *stufftable;
  24. >        extern STUFF stufftable[];
  25. >with respect to the code generated when I reference stufftable, i.e.:
  26. >        stufftable[i].xxx=...
  27. >and explain why it is so dangerous here, but it's perfectly ok
  28. >to use a pointer or a [] in a function declaration.
  29. >-- 
  30. >John A. Grant                                           jagrant@emr1.emr.ca
  31. >Airborne Geophysics
  32. >Geological Survey of Canada, Ottawa
  33. >
  34.  
  35. The difference is very simple:
  36.  
  37.     extern STUFF *stufftable
  38.  
  39. tells the complier that you have a global variable which is a POINTER to
  40. a "stufftable".  ie, the global quantity is a 2 or 4-byte pointer.
  41.  
  42.     extern STUFF stufftable[]
  43.  
  44. tells the compiler that you have a global ARRAY of STUFFs.
  45.  
  46. The two things are totally different.  The reason that it doesn't matter
  47. in a function declaration is that passing the name of an array to a function
  48. is the same as passing a pointer to the start of the array.
  49.  
  50. Hope this helps,
  51. -- 
  52. --------------------------------------------------------------------------
  53. | Chris Marriott                           | chris@chrism.demon.co.uk    |
  54. | Warrington, UK                           | BIX: cmarriott              |
  55. | (Still awaiting inspiration              | CIX: cmarriott              |
  56. |  for a witty .sig .... )                 | CompuServe: 100113,1140     |
  57. --------------------------------------------------------------------------
  58.  
  59.