Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/17/84; site opus.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!hao!nbires!opus!rcd From: rcd@opus.UUCP (Dick Dunn) Newsgroups: net.lang.c Subject: Re: Type modifiers in C (scope/extent discussion) Message-ID: <199@opus.UUCP> Date: Mon, 4-Nov-85 03:39:41 EST Article-I.D.: opus.199 Posted: Mon Nov 4 03:39:41 1985 Date-Received: Tue, 5-Nov-85 07:23:39 EST References: <943@lll-crg.ARpA> <177@opus.UUCP> <389@graffiti.UUCP> Organization: NBI,Inc, Boulder CO Lines: 41 > > ...(In some > > languages it would be prohibited to assign the address of an automatic > > variable to a more global pointer--i.e., a pointer whose extent exceeds > > that of the variable.) > > I hope they never put that in 'C'. After all... > > char *myname; > ... > main(ac, av) > int ac; > char **av; > { > ... > myname=av[0]; > ... > } This example would not, in fact, violate the rule given above. It DOES represent one of the cases where the rule is difficult to enforce. If one were to check the assignment of av[0] to myname, it would be necessary to know the extent of the object referenced by av. In the case shown, it's easy to see; the argument vector exists for the entire execution of the program. However, it's hard to establish this, and in some cases you won't be able to figure it out at compile time. In that case you can: - punt the check, which leaves a hole in what's supposed to be a useful check - issue a warning message, annoying everyone without telling them anything that they'll pay attention to - reject anything that doesn't obviously meet the constraint, which will rule out some useful, correct programs Philosophically, the third choice is the easiest for me to buy into, and it would rule out da Silva's example. Of course, this would only be happening in some language other than C, and one might decide in such a language to make things like the argument and environment string vectors global variables rather than main-program arguments. In other words, with different language rules you just do some things differently. -- Dick Dunn {hao,ucbvax,allegra}!nbires!rcd (303)444-5710 x3086 ...Never attribute to malice what can be adequately explained by stupidity.