home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- 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
- From: misar@rbg.informatik.th-darmstadt.de (walter misar)
- Subject: Re: How does the Address-of Operator (&) really work?
- Sender: news@news.th-darmstadt.de (The News System)
- Message-ID: <1992Nov12.160732@rbg.informatik.th-darmstadt.de>
- Date: Thu, 12 Nov 1992 15:07:32 GMT
- References: <1ds9htINNd81@agate.berkeley.edu>
- Nntp-Posting-Host: rbhp58.rbg.informatik.th-darmstadt.de
- Organization: TU Darmstadt
- Lines: 45
-
- In article <1ds9htINNd81@agate.berkeley.edu>, achoi@soda.berkeley.edu (Andrew Choi) writes:
- > Hi netters:
- >
- > I was told that the address-of operator & (along with sizeof)
- > is done at compilation done, therefore, it becomes legal to
- > do the followings:
- >
- > &(((struct S *) NULL)->field)
-
- Use offsetof (defined in stddef.h) instead.:
- offsetof(struct S,field)
-
- > However, what I don't understand is how it works under multiple
- > files. Considered the followings:
- >
- > /* file "foo.c" */
- >
- > char *a = "This is a test";
- >
- > /* file "bar.c" */
- >
- > char **b = &a; /* note that char *b = a; is ILLEGAL */
- >
- > When the 2 files, "bar.c" and "foo.c" are separately compiled,
- > what does the compiler put for "&a", since it does not know where
- > the definition for "a" is?
-
- That's the job of the linker (/bin/ld on UNIX). In the .o files the compiler
- stores the names and the positions in the code of all variables that have
- external linkage. So bar.o contains a dummy-adress instead of &a and the
- linker exchanges it with the real value found in foo.o .
-
- > Also, I need a definitive bible to the C language. What book(s)
- > are considered to be the bible for the C language?
-
- Definitely K&R ( 2nd edition ANSI) :
- The C Programming Language 2nd edition
- Brian W. Kernighan
- Dennis M. Ritchie
- Prentice Hall
- ISBN 0-13-110362-8
-
- --
- Walter Misar
- misar@rbhp56.rbg.informatik.th-darmstadt.de
-