Global variables

Chris Torek chris at trantor.umd.edu
Sat Feb 20 23:23:01 AEST 1988


In article <2302 at umd5.umd.edu> I wrote:
>>All[*] global and static data in C is either initialised by the programmer
>>(in which case, if it does not have the proper value on startup, the
>>compiler is broken) or not initialised by the programmer (in which case,
>>if it does not have zero values[**] on startup, the compiler is broken).
[the footnotes [*] and [**] vanished]

In article <987 at ssc-bee.ssc-vax.UUCP> lee at ssc-vax.UUCP (Lee Carver) writes:
>[flame on]
>So, you like the system to do things FOR you.

Indeed I do.  A system that just sits there passively, consuming
electricity but never acting, is hardly useful.  :-)

>I bet you like implict declarations.

Not particularly.  If, however, they were in the language, and
someone claimed that an undeclared variable were an error, I would
post a followup saying `no'.  Fortunately, implicit variable
declarations are not in the C language, although implicit function
declarations are.

>NEVER, NEVER, NEVER assume the system is going to put something
>there unless you explicitly request it.

Fine.  But if you want to put it that way, you must also acknowlege
that the language *definition* says that if I write

	f()
	{
		static int k;
		...

I have then `explicitly' (not very!) requested that k be set to
zero by the first call to f(), and that it retain the value it had
before on the next call to f()---just as I have declared the function
f() to return a value of type `int'.

You may not like it----indeed, *I* may not like it; I have not told
you whether I like it, just what the language definition says---
but that is the way it must be, or it is not a C compiler.  Or to
put it another way, you may assume anything that the language allows
you to assume, but not more.  You may, of course, assume less, as
I did indeed mention in <2302 at umd5.umd.edu>.
-- 
In-Real-Life: Chris Torek, Univ of MD Computer Science, +1 301 454 7163
(hiding out on trantor.umd.edu until mimsy is reassembled in its new home)
Domain: chris at mimsy.umd.edu		Path: not easily reachable



More information about the Comp.lang.c mailing list