Type modifiers in C (scope/extent discussion)

Dick Dunn rcd at opus.UUCP
Mon Nov 4 18:39:41 AEST 1985


> > ...(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.



More information about the Comp.lang.c mailing list