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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
  3. From: misar@rbg.informatik.th-darmstadt.de (Walter Misar)
  4. Subject: Re: extern: interesting case...
  5. Sender: news@news.th-darmstadt.de (The News System)
  6. Message-ID: <1993Jan6.200359@rbg.informatik.th-darmstadt.de>
  7. Date: Wed, 6 Jan 1993 19:03:59 GMT
  8. References:  <bibhas.726341439@femto.engr.mun.ca>
  9. Nntp-Posting-Host: rbhp58.rbg.informatik.th-darmstadt.de
  10. Organization: TH Darmstadt
  11. Keywords: extern
  12. Lines: 29
  13.  
  14. In article <bibhas.726341439@femto.engr.mun.ca>, bibhas@pico.engr.mun.ca (Bibhas Bhattacharya) writes:
  15. > When I declare:
  16. > extern char line[];
  17. > for the variable "line" which was defined in another file as:
  18. > char line[80];
  19. > everything works fine. But when I do:
  20. > extern char *line;
  21. > the program dumps core. I can't figure out the difference, especially when
  22. > extern declaration is not supposed to reserve any memory or anything. When
  23. > I looked up K&R, the correct declaration would be: extern char line[];.
  24.  
  25. A pointer isn't the same as an array. (Try compiling extern char *line;
  26. extern char line[80]; => conflicting types for `line')
  27. Given extern char line[], the compiler knows, that line is an constant adress,
  28. where chars are stored. Given  extern char *line, the compiler looks at line
  29. as a variable (=constant adress) where a pointer is stored, which points to
  30. chars.
  31.  
  32. In assembler this would look like this:
  33.  
  34. line: dc.b "text",0    ; char line[]="text";
  35. +--------------------------------------------
  36. text: dc.b "text",0
  37. line: dc.l text        ; char *line="text";    
  38.  
  39. -- 
  40. Walter Misar                                | It is impossible to enjoy
  41. misar@rbg.informatik.th-darmstadt.de        | idling thoroughly unless
  42.                                             | one has plenty of work to do.
  43.