home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16412 < prev    next >
Encoding:
Text File  |  1992-11-12  |  1.9 KB  |  58 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!mcsun!Germany.EU.net!rrz.uni-koeln.de!unidui!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: How does the Address-of Operator (&) really work?
  5. Sender: news@news.th-darmstadt.de (The News System)
  6. Message-ID: <1992Nov12.160732@rbg.informatik.th-darmstadt.de>
  7. Date: Thu, 12 Nov 1992 15:07:32 GMT
  8. References:  <1ds9htINNd81@agate.berkeley.edu>
  9. Nntp-Posting-Host: rbhp58.rbg.informatik.th-darmstadt.de
  10. Organization: TU Darmstadt
  11. Lines: 45
  12.  
  13. In article <1ds9htINNd81@agate.berkeley.edu>, achoi@soda.berkeley.edu (Andrew Choi) writes:
  14. > Hi netters:
  15. >   I was told that the address-of operator & (along with sizeof)
  16. > is done at compilation done, therefore, it becomes legal to
  17. > do the followings:
  18. >   &(((struct S *) NULL)->field)
  19.  
  20. Use offsetof (defined in stddef.h) instead.:
  21. offsetof(struct S,field)
  22.  
  23. > However, what I don't understand is how it works under multiple
  24. > files.  Considered the followings:
  25. >   /* file "foo.c" */
  26. >   char *a = "This is a test";
  27. >   /* file "bar.c" */
  28. >   char **b = &a;    /* note that char *b = a; is ILLEGAL */
  29. >
  30. > When the 2 files, "bar.c" and "foo.c" are separately compiled,
  31. > what does the compiler put for "&a", since it does not know where
  32. > the definition for "a" is?
  33.  
  34. That's the job of the linker (/bin/ld on UNIX). In the .o files the compiler
  35. stores the names and the positions in the code of all variables that have
  36. external linkage. So bar.o contains a dummy-adress instead of &a and the
  37. linker exchanges it with the real value found in foo.o .  
  38.  
  39. >   Also, I need a definitive bible to the C language.  What book(s)
  40. > are considered to be the bible for the C language?
  41.  
  42. Definitely K&R ( 2nd edition ANSI) :
  43. The C Programming Language 2nd edition
  44. Brian W. Kernighan
  45. Dennis M. Ritchie
  46. Prentice Hall
  47. ISBN 0-13-110362-8
  48.  
  49. -- 
  50. Walter Misar
  51. misar@rbhp56.rbg.informatik.th-darmstadt.de
  52.