Re: Global variables defined several times.
In message [EMAIL PROTECTED] David Malone writes: : I can't find my second edition at the moment. This behavior is : commented on in the C FAQ as something the ANSI standard describes : as a common extension. (http://www.eskimo.com/~scs/C-faq/q1.7.html) : It also seems to suggest it is mostly a Unix thing. VMS's DEC CC does the same thing as our tool chain. At least on the VMS 4.4 system I used in college. It got lots of other things "different" than the unix compilers we were using (pcc derived things for sun3 and sun4), but this it did the same. C++ requires exactly one definition, but can have many declarations (eg only one int foo, but many extern int foo). Actually, conforming C++ compilers may require exactly one definition. This is listed in the appendix of one of the Stroustup books as being a departure from plain old C. Warner To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Global variables defined several times.
I've just noticed that usr.bin/ftp/ftp_var.h defines a large selection of global variables, and then this header file is included in multiple C source files. I thought this should lead to one copy of the global varible per source file, and then a warning or error at link time due to symbols being defined multiple times. This doesn't seem to be the case with the toolchain - you seem to get one copy of each variable for the final linked unit. I tested this with some different compilers and linkers - SAS/C on the Amiga and CodeWarrior on the Mac seem to complain about the symbols turning up twice. AIX and Digital Unix's compilers seem to have the same behavior as the FreeBSD toolchain. I guess this means it's a traditional Unix feature? I did look at the object files with nm, and it shows these symbols with type "C" - unfortunately this isn't explained in the nm or objdump man pages, and there doesn't seem to be an obvious place to look in the rest of the info pages. David. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Global variables defined several times.
In message [EMAIL PROTECTED], David Malone writes: I've just noticed that usr.bin/ftp/ftp_var.h defines a large selection of global variables, and then this header file is included in multiple C source files. I thought this should lead to one copy of the global varible per source file, and then a warning or error at link time due to symbols being defined multiple times. This doesn't seem to be the case with the toolchain - you seem to get one copy of each variable for the final linked unit. This is called "common" variables. They're documented with that behaviour in the old and new testament. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 [EMAIL PROTECTED] | TCP/IP since RFC 956 FreeBSD coreteam member | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Global variables defined several times.
In message [EMAIL PROTECTED], David Malone writes: I've just noticed that usr.bin/ftp/ftp_var.h defines a large selection of global variables, and then this header file is included in multiple C source files. I thought this should lead to one copy of the global varible per source file, and then a warning or error at link time due to symbols being defined multiple times. This doesn't seem to be the case with the toolchain - you seem to get one copy of each variable for the final linked unit. This is called "common" variables. They're documented with that behaviour in the old and new testament. In the KR1 I have to hand, the last line of page 76 and top of page 77 say: If the lines int sp; double val[MAXVAL]; apprar outside any function, they \emph{define} the expernal variables sp and val... Further down page 77: There must be only one \emph{definition} of an external variable among all the files that make up the source program; other files may contain extern declarations to access it. I can't find my second edition at the moment. This behavior is commented on in the C FAQ as something the ANSI standard describes as a common extension. (http://www.eskimo.com/~scs/C-faq/q1.7.html) It also seems to suggest it is mostly a Unix thing. David. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message