rjchen@phoenix.Princeton.EDU (Raymond Juimong Chen) (02/17/88)
To get back to the original question (do we ever do that here?) From someone whose attribution has since vanished: >The manual seems to indicate that only initialized global >data will go here, but isn't all global data implicitly >initialized to zero if not otherwise specified? I believe that global data initialized to zero go into a special segment called "bss". What it stands for is beyond me. What it means is (I think) that when the program is loaded, the loader allocates the requisite amount of space and initializes it to zero at runtime. This is meant to save space in the executable. Corrections welcomed. flames slightly less so. -- Raymond Chen UUCP: ...allegra!princeton!{phoenix|pucc}!rjchen BITNET: rjchen@phoenix.UUCP, rjchen@pucc ARPA: rjchen@phoenix.PRINCETON.EDU "Say something, please! ('Yes' would be best.)" - The Doctor
karl@haddock.ISC.COM (Karl Heuer) (02/17/88)
In article <1744@phoenix.Princeton.EDU> rjchen@phoenix.Princeton.EDU (Raymond Chen) writes: >I believe that global data initialized to zero go into [the bss segment]. >... When the program is loaded, the loader allocates the requisite amount of >space and initializes it to zero at runtime. Close enough. But this is a property of one particular implementation, not a description of C in general. Note also that if a floating-point zero or a null pointer has some representation other than all-bits-zero, then any floating or pointer object with static duration and no explicit initializer would not be correctly handled by this gimmick. (Unless you have a really smart loader.) The compiler is obliged to initialize it to a zero of the appropriate type, which can (of course) be placed in the data segment along with the explicitly initialized variables. >What [bss] stands for is beyond me. Oh no. Followups on this subtopic, please redirect to comp.misc and put "bss" in the subject line so I can kill it. I hope this doesn't get as bad as the "foo" postings a while back. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
fox@alice.marlow.reuters.co.uk (Paul Fox) (02/27/88)
In article <1744@phoenix.Princeton.EDU>, rjchen@phoenix.Princeton.EDU (Raymond Juimong Chen) writes: > I believe that global data initialized to zero go into a special > segment called "bss". What it stands for is beyond me. ... 'bss', I believe, comes from the early IBM assemblers. It stands for 'Block Started by Symbol'. This was/is a pseudo op which reserves spaces in the data area, used as in: fred: bss 12 // Reserve 12 bytes. [Excuse the syntax if its wrong]. I presume that this pseudo op was present in the early PDP-7 & 11 assemblers as well. (On the PDP-10, BLKZ or BLK was used).
mouse@mcgill-vision.UUCP (der Mouse) (03/08/88)
In article <1744@phoenix.Princeton.EDU>, rjchen@phoenix.Princeton.EDU (Raymond Juimong Chen) writes: > From someone whose attribution has since vanished: >> The manual seems to indicate that only initialized global data will >> go here, but isn't all global data implicitly initialized to zero if >> not otherwise specified? All statically-allocated data are initialized to zero unless they are explicitly initialized to something else. This includes both things declared static and normal global data. > I believe that global data initialized to zero go into a special > segment called "bss". What it means is (I think) that when the > program is loaded, the loader allocates the requisite amount of space > and initializes it to zero at runtime. This is a UNIXism; not all systems have anything like UNIX's bss segment, and even fewer of them actually call it bss. As to what it means, you are perfectly correct. It's sort of a trivial form of data compression: it's something like run-length compression for zero data only. On the other hand, this has its ambiguities. Imagine a machine on which integer zero, floating zero, and null pointer have three different bit patterns. Now, what is the following datum on program startup? Presumably it's one of the three, or possibly all-bits-zero regardless of whether this matches any of the above three.... Could someone with access to the draft clear this up? union { int i; float f; char *cp; } funny; der Mouse uucp: mouse@mcgill-vision.uucp arpa: mouse@larry.mcrcim.mcgill.edu
gwyn@brl-smoke.ARPA (Doug Gwyn ) (03/24/88)
In article <978@mcgill-vision.UUCP> mouse@mcgill-vision.UUCP (der Mouse) writes: >Could someone with access to the draft clear this up? Without even looking it up, I can tell you that the default initial values are required to be zeros of the right type. Pointers would have null pointer values, integer types all 0 bits (in effect), and floating point data would have 0.0 even if the bit pattern required for this is not all 0 bits. On many implementations, filling BSS with all-0 bytes will do the trick, but there are those that require more elaborate initialization.
henry@utzoo.uucp (Henry Spencer) (03/26/88)
> ... Imagine a machine on > which integer zero, floating zero, and null pointer have three > different bit patterns. Now, what is the following datum on program > startup? Presumably it's one of the three, or possibly all-bits-zero > regardless of whether this matches any of the above three.... Could > someone with access to the draft clear this up? > > union { int i; float f; char *cp; } funny; It gets initialized as if by "funny.i = 0". X3J11 says that initialization of unions is by their first member. (Please don't start another flame war over this, we've been through it several times before. X3J11 picked the minimum solution that made the initial state of static unions well-defined, a solution which had been used with some success by existing compilers. Nobody disputes that it is ugly and inflexible; if you wish to propose a better alternative, DON'T post it to the net -- implement it in your local C compiler, use it for a couple of years, and then submit it to X3J11 when the C standard comes up for revision. Implementation and successful use carries far more weight than words on paper.) -- "Noalias must go. This is | Henry Spencer @ U of Toronto Zoology non-negotiable." --DMR | {allegra,ihnp4,decvax,utai}!utzoo!henry