📄 common.html
字号:
<html><!-- Mirrored from c-faq.com/decl/common.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:02:57 GMT --><head><title>a ``common'' extension</title></head><body>[This is a mail reply I sent to someone who wondered what I meant by``this behavior is mentioned as a `common extension' by the ANSI Standard,no pun intended.'']<!-- Date: Sun, 03 Dec 2000 09:07:08 -0600 --><!-- Message-Id: <2000Dec03.0907.scs.0011@rutabaga.scs.ndip.eskimo.net> --><p>I guess it's sorta obscure if you don't know too much about FORTRAN.<p>In FORTRAN, there were data structures called ``COMMON blocks''which were, as I recall, the main way of sharing global databetween the modules of a separately-compiled program. They werea nuisance to use: you had to mention the same variable names,in the same order, in the COMMON directive at the top of eachsource file. (Actually, you could use deliberate mismatches ofvariable names or types in COMMON blocks to inspect the bits ofa value of one type as if it were another, much as you might dowith a union in C.) When you added another variable to a COMMONblock, you had to remember to add it to all the definitions ofthat COMMON block, in all source files. If you'd never heard ofpreprocessors or source file inclusion (that is, of mechanismslike C's <TT>#include</TT>) you invented the idea for yourself, and wishedthat it existed in FORTRAN. (It didn't, at least not in thestandard versions of FORTRAN when I used it, although somecompilers -- probably including Unix's -- supported it as anextension.)<p>That's by way of background. In C, there's always been someuncertainty about the precise way global variables are handled,which is of course why FAQ 1.7 exists. In particular, in theclassic implementations of C, it was possible to define aglobal variable like<p><pre> int i;</pre>in several source files, and as long as no more than one ofthe definitions had an explicit initializer, the linker wouldrealize that they were all the same variable, and essentiallyoverlay them in memory. This was referred to as the ``commonmodel'', not because it was popular or widespread (though itwas), but because it was reminiscent of FORTRAN COMMON blocks.</body><!-- Mirrored from c-faq.com/decl/common.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:02:57 GMT --></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -