Type modifiers in C (scope/extent discussion)

Lowell Savage savage at ssc-vax.UUCP
Thu Nov 7 06:28:07 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];
> > 		...
> > 	}
I think that this rule is talking about something more like one of
the following cases:

	char *cpt;				ffoo()
	...					{	char *cpt;
	foo()						cpt = foo();
	{						...
		char ch[10];			}
		...				foo()
		cpt = ch;			{	char ch[10];
		...					...
	}						return (ch);
						}
the C compiler should catch these (or at least lint should) since
'ch' may go away before the next time cpt is dereferenced.  Now
this should be okay if 'ch' is static, because then it will still
be around no matter when you dereference 'cpt'.  Also, you know
that the only way to get to 'ch' is to call foo, you can't just
use it.  Now if some idiot programmer still wants to muck around
with the data stored in 'ch' by dereferencing 'cpt', that's his
business.  But since (at least one of) the main purpose(s) of foo
is calculate 'ch' it shouldn't depend on any previous data in foo.


These are my own personal biases.  Anyone that wants to share them will
have to fill out a 100-page non-disclosure agreement in octuplicate
(without carbons), send all copies with 2 dollars for processing to
outer Tanzania, wait two years, and chant "Mousy Dung was a bad guy."
five hundred times.  All questions on this matter will be refered to
the Bureau of non-violent violence (BNVV)...or was that the Association
for the Promulgation of Persons Against Associations (APPAA)?

				There's more than one way to be savage
				Lowell Savage



More information about the Comp.lang.c mailing list