knudsen@ihnss.UUCP (07/22/83)
I write C code for 8086 systems with the .text and .data (constants
of course) in ROM and the .bss in RAM.
It has been my understanidng that our BTL C compiler (basic16)
will initalize variables if & only if you say so in the declarations.
There are two kinds: globals (declared outside any {}) that are
explicitly assigned to .bss addresses and known by name to
assemblers, loaders, linkers, and debuggers. The other kind,
declared inside a procedure (inlucding main()), are just stack-frame
and can't be traced. However, these get initialized (if you assk for it)
on every call. I don't know whether globals can be init'ed or not;
I always do these with code statements anyway.
Question: does init'ing vars in declarations buy you anything in
space or speed over doing it by actual statements in the body?
mike kchris@umcp-cs.UUCP (07/23/83)
Since the thing that started this discussion was Whitesmith C, let me
point out yet again that the problem is not that they don't set statics
to zero. They *do* set statics to zero -- try
main () { static x; putfmt ("x=%d\n", x); }
and you get zero (I forget if you use putfmt that way, but you probably
understand what I mean). The problem is that they don't create a
global variable unless you initialize it! Try
int var;
main () { foo (var); }
foo (n) int n; { }
Compile, and you get: "Undefined: var.". If you use
int var = <any integer> ;
it compiles correctly. But if you don't initialize it it's considered
*external*.
- Chris
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci
UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet: chris@umcp-cs
ARPA: chris.umcp-cs@UDel-Relay